Skip to content Skip to sidebar Skip to footer

How To Sort CSV Rows By A Single Column Using PANDAS Python

Currently on my project I am trying to sort the rows of a CVS sheet by a singular column, I am using PANDAS and I have seen several examples posted all around the internet, however

Solution 1:

databasefile = r"path"
databasefile2 = r"path"
db = pd.read_csv(databasefile, skip_blank_lines=True, names=['ExampleOne','ExampleTwo','ExampleThree','ExampleFour'], header=1)
print(db['ExampleOne'])
db.drop_duplicates(inplace=True)
db.sort_values(by=['ExampleOne'], ascending=True).to_csv(databasefile, index=False)

Here is a solution to your problem.


Post a Comment for "How To Sort CSV Rows By A Single Column Using PANDAS Python"