我有一个包含多行和列的csv文件。 我想使用python和bubblesort按特定列对文件进行排序。 例如:
输入csv文件:
Daniel,New York,23456,Gaming Melinda,Washington,45678,Sports Dave,Chicago,12345,Hiking Ross,Boston,34567,Chess
输出:
Dave,Chicago,12345,Hiking Daniel,New York,23456,Gaming Ross,Boston,34567,Chess Melinda,Washington,45678,Sports
在本例中,应按第三列对行进行排序
到目前为止,我只能对第三列进行排序,但其他列保持不变
下面是一个使用python内置csv模块的实现。此解决方案假定输入csv文件位于test.csv中,并且您希望输出位于output.csv中
注意:您还可以使用pandas读取csv文件,并使用pandas中更快的内置算法进行排序
相关问题 更多 >
编程相关推荐