Reputation: 660
When I try to use x = pandas.Series.from_csv('File_name.csv', header = None)
It throws an error saying IndexError: single positional indexer is out-of-bounds.
However, If I read it as dataframe and then extract series, it works fine.
x = pandas.read_csv('File_name.csv', header = None)[0]
What could be wrong with first method?
Upvotes: 6
Views: 5023
Reputation: 604
There is 2 option read series from csv file;
pd.Series.from_csv('File_name.csv')
pd.read_csv('File_name.csv', squeeze=True)
My prefer is; using squeeze=True with read_csv
Upvotes: 3
Reputation: 5223
Add index_col=None parameter, seems it is reading entire file in one column and default first column is treated as index.
Pandas documentation says Series.from_csv is discouraged. read_csv is much more powerful alternative you should use that.
Upvotes: 3