简体   繁体   中英

order only number in dataframe rows by rows import from csv

I want to get ascending order all number of dataframe imported from a CSV file row-by-row:

df_tirage = pd.read_csv('lotodata.csv', sep = ',', usecols=['day','month_year','num0','num1','num2','num3','num4','chance'])
for eachline in df_tirage:
    line = map(str, eachline.split(","))
    sorted_line = sorted(line)

If I'm understanding it correctly, something might the following should do the trick.

df_tirage = pd.read_csv('lotodata.csv', sep = ',', usecols=['day','month_year','num0','num1','num2','num3','num4','chance'])

def sorter(num_arr):
    return np.sort(num_arr)

df_tirage[['num0', 'num1', 'num2', 'num3', 'num4']] = df_tirage.apply(lambda row : sorter(row[2:-1]), axis=1, result_type='expand')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM