1

I have problem with reading univariate time series in python with read_csv command. My csv file contain two columns, the first column is Date and second necessary data. With command series=read_csv('K.csv', header=0, parse_dates=[0], index_col=0, squeeze=True) I got 4 columns, the first is data for which I am looking for and three columns are NaN columns.

Date                        GWL            Unnamed: 2  Unnamed: 3  Unnamed: 4                            
01/01/2004                  136.61         NaN         NaN         NaN

I don't know how to read this univariate time series, and to have only Date and my data as column (just the first two columns from this quoted part above)?

nick_name
  • 161
  • 10
  • Does this answer your question? [Get pandas.read\_csv to read empty values as empty string instead of nan](https://stackoverflow.com/questions/10867028/get-pandas-read-csv-to-read-empty-values-as-empty-string-instead-of-nan) – dank8 Mar 03 '23 at 02:47

1 Answers1

4

Your .csv probably contains additional commas at the end e.g.

Date,GWL,,,
01/01/2004,136.61,,,

Add usecols=[0,1] to the read_csv() call.

hongsy
  • 1,498
  • 1
  • 27
  • 39