Excel file:
5432
321
9870
import pandas as pd
file = 'read.xlsx'
df1 = pd.read_excel(file)
print(df1)
I want to sort the number within the number into
2345
1234
0789
Excel file:
5432
321
9870
import pandas as pd
file = 'read.xlsx'
df1 = pd.read_excel(file)
print(df1)
I want to sort the number within the number into
2345
1234
0789
Use list comprehension with convert values to string
s with sorted
:
#read excel file without header, so column is 0
df1 = pd.read_excel(file, header=None)
df1['new'] = [''.join(sorted(str(x))) for x in df1[0]]
print (df1)
col
0 2345
1 1234
2 0789