2

我试图从本地存储在我的计算机上的 csv 中读取数据帧。数据为 csv 格式,格式为:

date,total_bytes
2018-09-02,1.96E+14
2018-09-04,1.94E+14
2018-09-09,2.15E+14
...

我的代码如下所示:

from pandas import read_csv
from pandas import datetime
from matplotlib import pyplot
series = 
read_csv('/Users/taylorjewell/Desktop/dataset_size_daily.csv')
print(series.head())
series.plot()
pyplot.show()

当我尝试运行此文件时,我得到:文件“dataset_size_daily.csv”,第 2 行 2018-09-02,1.96E+14 语法错误:无效令牌

我哪里错了,非常感谢您的帮助!

4

2 回答 2

0

As weird as it might seem, it looks like you're trying to execute your CSV file as Python code, instead of the actual python script. I was even able to reproduce your error by running python asdf.csv:

sh-5.0$ cat asdf.csv
date,total_bytes
2018-09-02,1.96E+14
2018-09-04,1.94E+14
2018-09-09,2.15E+14
sh-5.0$ python asdf.csv
  File "asdf.csv", line 2
    2018-09-02,1.96E+14
          ^
SyntaxError: invalid token
sh-5.0$

So... it should go without saying, but run the .py file, not the .csv one...

于 2019-08-20T00:41:35.137 回答
-1

您正在尝试读取没有扩展名的 CSV 文件,它应该类似于 pd.read_csv('data.csv')

于 2019-08-12T19:20:04.087 回答