我从不使用python,所以不知道如何解决这个问题。我有一个excel/csv文件,格式如下。我需要找到所有具有匹配infid值的行,并将这些行输出到新文件中的同一行。你知道吗
你知道吗我的文件.csv地址:
ROUTE_NAME CURR_VOL IN_FID NEAR_RANK
test11 test11 1 test11
test12 test12 1 test12
test2 test2 2 test2
test3 test3 3 test3
test31 test 3 test31
期望输出:
IN_FID ROUTE_NAME1 NEAR_RANK1 ROUTE_NAME2 NEAR_RANK2
1 test11 test11 test12 test12
2 test2 test2 null null
3 test3 test3 test31 test31
我一开始只是尝试用python操作csv,但我想知道是否有像pandas这样的库更适合使用?你知道吗
#!/usr/bin/python
import csv
profile_to_search = input()
with open('myfile.csv', 'rt') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
if profile_to_search == row[2]:
print(row)
我走了这么远,然后意识到我不知道自己在做什么。你知道吗
只是一个
cumcount
那么应该是简单的pivot
问题如果我了解您想要的是什么…假设您想要的输出缺少
CURR_VOL
列:更有效的方法是使用
map
:相关问题 更多 >
编程相关推荐