您好我有一個CSV文件,我需要使用Python 3提取特定的列值3
下面這個文件中提取特定的列中的值是我的代碼:
from csv import reader
with open('', "/Users/tinasosiak/Documents/Tender1copy.csv") as output, open("/Users/tinasosiak/Documents/Tender1.csv", newlines='') as input:
for row in reader("/Users/tinasosiak/Documents/Tender1.csv"):
print(row[2], file="/Users/tinasosiak/Documents/Tender1copy.csv")
的CSV文件: enter image description here
,當我跑我的pogram我得到以下錯誤:
Traceback (most recent call last): File "/Users/tinasosiak/Documents/word_cloud/why.py", line 3, in with open('', "/Users/tinasosiak/Documents/Tender1copy.csv") as output, open("/Users/tinasosiak/Documents/Tender1.csv", newlines='') as input: ValueError: invalid mode: '/Users/tinasosiak/Documents/Tender1copy.csv'
你的錯誤是很清楚'的open()'2位置參數表是意思是,'開放(,)'看到的文檔:https://docs.python.org /3.6/library/functions.html#open。您應該閱讀'csv'文檔,'reader()'接受一個文件對象,例如'input' - 不是文件名。 –
AChampion