I create a pandas Series, I then output it to a CSV file. Then I try to open that CSV file in another worksheet using pandas.read_csv. I then check the type and it is now showing it as a DataFrame object??
I tried to fix it using-
series = df.transpose()[0]
and
df.ix[0]
but this did not work for me.
Any help is appreciated, thanks!
Here is an example of my problem-
I output my series to CSV and the CSV sheet then looks like this-
a,2
b,4
c,6
d,8
e,10
I then read the CSV into another worksheet using pd.read_csv(" "). When I print this out here is what shows up-
a 2
0 b 4
1 c 6
2 d 8
3 e 10
it is now a dataframe, and it now has columns "a" and "2", I can do header=None when reading the CSV to get rid of the columns...but the index is still 0,1,2,3 and its a dataframe.
You need to pass this option to read_csv():
squeeze : boolean, default False
If the parsed data only contains one column then return a Series
Edit: Given the additional details you added, the full command you want is:
pd.read_csv('foo.txt', header=None, squeeze=True, index_col=0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With