我是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