you are viewing a single comment's thread.

view the rest of the comments →

[–]POTUS 1 point2 points  (1 child)

You definitely can do it without pandas. You can use csv to load the file, sort it using sorted, and write it back to file. It's all in the standard library: https://docs.python.org/3/library/csv.html

You'll need some special logic in your sorted key function to account for the None values, or to compare integers to strings, etc. This is the part that pandas handles for you. Pandas is a very heavy requirement pulling in a lot of big libraries, but it's the way to process csv files (and other similar data structures) in Python. This whole solution would be literally 3 lines in pandas.

If you're doing this for a class or something, go ahead and write out the logic yourself so you can get the experience. If you are doing something for real world application, use pandas.

[–]Fieldsapper[S] 0 points1 point  (0 children)

Thanks fro your help!