2

I am trying to simply read in a dataframe from a csv that is stored locally on my computer. The data is in a csv and is of the format:

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

My code looks like:

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()

When I try to run this file I get: File "dataset_size_daily.csv", line 2 2018-09-02,1.96E+14 Syntax Error: Invalid token

Where am I going wrong, your help would be much appreciated!

jewelltaylor9430
  • 109
  • 1
  • 15
  • What is the separator you're using? There might be an extra comma where it shouldn't be, thus invalidating the whole file. – Nicolò Gasparini Aug 12 '19 at 19:28
  • I have validated the input which is only 52 rows to make sure this isnt the case and I am still getting the same error :( – jewelltaylor9430 Aug 12 '19 at 20:22
  • Please open your csv with a text editor and paste exactly the top few rows into the body of your post so we can reproduce. Right now, I cannot reproduce your error. – Parfait Aug 12 '19 at 21:22
  • that is exactly the top few rows of the csv, are you telling me that it is running successfully on your machine? – jewelltaylor9430 Aug 12 '19 at 21:25

2 Answers2

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...

caxcaxcoatl
  • 8,472
  • 1
  • 13
  • 21
-1

You're trying to read CSV file without the extenction, it should be like pd.read_csv('data.csv')

Dr Sheldon
  • 176
  • 1
  • 14