我想在Python3中完成一項任務。這是非常相似的pdf找到here從.csv文件獲取數據,分析,產生輸出 - python3
我對如何獲得我需要的信息的執行有幾個問題,如果可能的話,一些代碼可以移動我。我是python的新手。就像我現在的代碼一樣,在運行一個函數來嘗試讀取數據之後,我總是收到錯誤"directory not found"
。我知道.csv
文件應該位於我將其保存到WingIDE中的目錄中,但我無法使其正常工作。
我的第一個問題是獲得.csv文件中的每一行從我get_file_list閱讀後,什麼是採取每個類別,把它扔進了效率方程式的最佳方式是什麼?
這裏是我的get_data_list
功能:
def get_data_list(filename):
data_file = open(filename, "r")
data_list = [ ]
for line_str in data_file:
data_list.append(line_str.strip().split(','))
return data_list
當我運行get_data_list("player_regular_season.csv")
我得到以下錯誤:
builtins.IOError: [Errno 2] No such file or directory:'player_regular_season.csv'
嘗試指定完整的文件路徑(不要忘了逃跑斜線作爲''\\或使用'/'代替)。你也可能想使用['csv'](http://docs.python.org/library/csv.html)模塊。 – 2012-07-11 21:56:54
您應該添加[家庭作業]標籤以保持公平。 – pepr 2012-07-12 06:36:35