I would like to sort the following CSV file by the first column (by name) however I would like it to exclude the first row as that is what my python file uses to determine which column is which.
name,age,email
Fin H,14,test@gmail.com
Harvey G,14,test2@gmail.com
name,1,2323
It needs to read the file, sort it by the first column (excluding the first row) and then write the sorted version back to the same file.
Thanks.
import pandas as pd
import numpy as np
df = pd.read_csv('input', sep = ',')
df = df.sort_values(by = ['name'])
df.to_csv('input', index = False)
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.