[英]creating visualization in Python : EmptyDataError
我使用python讀取csv文件並創建一些數字:
import csv
Teaching=open('A.csv','rb')
reader = csv.reader(Teaching)
#type is list.....
#create figure1,2,3 by using bokeh
#.....
import pandas as pd
df = pd.read_csv(Teaching)
#create figure4 by using bokeh
#I use series type to create a scatter plot
它有一個錯誤:EmptyDataError:沒有要從文件中解析的列
EmptyDataError Traceback (most recent call last)
<ipython-input-45-c97e3d2be637> in <module>()
----> 1 df = pd.read_csv(Teaching)
如果我重新打開CSV文件,它將起作用並創建散點圖
請告訴我為什么,如何修改? 謝謝
迭代file
對象后,讀取到文件的末尾,下次要讀取數據時,它將返回此錯誤:
pandas.io.common.EmptyDataError: No columns to parse from file
因此,您可以嘗試重新打開它或使用file.seek(0)
重新定位到文件的開頭。
代碼應如下所示:
import csv
Teaching=open('a.csv','rb')
reader = csv.reader(Teaching)
for r in reader:
print(r)
import pandas as pd
Teaching.seek(0)
df = pd.read_csv(Teaching)
print(df)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.