I use python to read a csv file and create some figures:
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
It has an error: EmptyDataError: No columns to parse from file
EmptyDataError Traceback (most recent call last)
<ipython-input-45-c97e3d2be637> in <module>()
----> 1 df = pd.read_csv(Teaching)
If I reopen the CSV file, it will work and create a scatter plot
Please tell me why, how to modify? Thank you
After you iterate the file
object, you read to the end of the file, next time you want to read the data, it will return this error:
pandas.io.common.EmptyDataError: No columns to parse from file
So you can try to reopen it or use file.seek(0)
to reposition to the start of the file.
The code should be like this:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.