I am trying to read a txt file into python and getting the above error. I want to convert each line into 3 columns. The text file looks like this -ValueError異常:沒有足夠的數值解壓縮(預計3,拿到1)
1714,Sales,Math
10070,Research,Science
1704,Developer,History
32696,QA,Math
16421,Marketing,Science
25925,Sales,History
我的代碼如下所示:
import pandas as pd
a=open('/Users/mezbahuddin/Downloads/dept_course.txt')
b=a.read()
for line in b:
g,h,i=line.strip().split(",",2)
print(g[0],h[0],i[0])
Anyhelp將不勝感激。謝謝
您是否曾在本網站搜索過類似的錯誤訊息?你有沒有嘗試打印出中間值來驗證你的假設是正確的? –
仔細看看這條線'g,h,i = line.strip()。split(「,」,2)'。什麼將strip()。split(',',2)'return?還說'a = b.read()'沒有做你認爲它做的事。 –
@BryanOakley我做到了。沒有一個職位提供了明確的解決方案。 – mezz