我是Python新手,需要一些帮助才能获得调查结果。我有一个CSV文件,它看起来像这样:CSV文件的Python计数器
Person, Gender, Q1, Q2, Q3
professor, male, agree, not agree, agree
professor, male, agree, agree, agree
professor, female, neutral, not agree, agree
Professor, female, agree, agree, agree
student, female, agree, not agree, not agree
student, female, no answer, not agree, agree
student, male, no answer, no answer, agree
我想算每人性别产生不同的答案的次数。例如Q1:(教授,男性:同意,2),(教授,女性:同意1;中性1)等等。 到目前为止,我已经试过这样:
import csv
from collections import Counter
with open('survey.csv') as csvfile:
reader = csv.reader(csvfile, delimiter=',', dialect = csv.excel_tab)
counts = Counter(map(tuple,reader))
print [row for row in reader if row]
print list(csv.reader(csvfile))
但我觉得,因为我只有串,我没有得到任何结果。而且,我还不知道如何通过人/性别获取数据。 非常感谢!
使用['pandas'](http://pandas.pydata.org/pandas-docs/stable/10min.html) – Peter9192