@Uts is exactly right for Case 1. For Case 2, any 2-digit (or more) numbers will be transposed because they are treated as strings instead of delimited integer values that are represented as strings.
Please see Case 2b below for splitting and reversing the list of integers represented as strings.
import pandas as pd
print('Case 1 - x_val = lists of int')
df = pd.DataFrame({
'index':[1,2,3],
'x_val':[[1,2,3,4,5], [2,3,4,5,6], [6,7,8,9,10]]
})
print(df)
df['x_val'] = df['x_val'].apply(lambda x: list(reversed(x)))
print(df)
print('\nCase 2 - x_val = strings, string values will be reversed')
df = pd.DataFrame({
'index':[1,2,3],
'x_val':['[1,2,3,4,5]', '[2,3,4,5,6]', '[6,7,8,9,10]']
})
print(df)
df['x_val'] = df['x_val'].apply(lambda x: '['+x[-2:0:-1]+']')
print(df)
print('\nCase 2b - x_val = strings')
df = pd.DataFrame({
'index':[1,2,3],
'x_val':['[1,2,3,4,5]', '[2,3,4,5,6]', '[6,7,8,9,10]']
})
print(df)
df['x_val'] = df['x_val'].apply(lambda x: '['+','.join(el for el in
reversed(x[1:-1].split(',')))+']')
print(df)
Output:
Case 1 - x_val = lists of int
index x_val
0 1 [1, 2, 3, 4, 5]
1 2 [2, 3, 4, 5, 6]
2 3 [6, 7, 8, 9, 10]
index x_val
0 1 [5, 4, 3, 2, 1]
1 2 [6, 5, 4, 3, 2]
2 3 [10, 9, 8, 7, 6]
Case 2 - x_val = strings, string values will be reversed
index x_val
0 1 [1,2,3,4,5]
1 2 [2,3,4,5,6]
2 3 [6,7,8,9,10]
index x_val
0 1 [5,4,3,2,1]
1 2 [6,5,4,3,2]
2 3 [01,9,8,7,6]
Case 2b - x_val = strings
index x_val
0 1 [1,2,3,4,5]
1 2 [2,3,4,5,6]
2 3 [6,7,8,9,10]
index x_val
0 1 [5,4,3,2,1]
1 2 [6,5,4,3,2]
2 3 [10,9,8,7,6]