How to write/read pandas Series to/from csv?
pandas, python
Solution
In [3]: s.to_csv('/home/wesm/tmp/sfoo.csv')
In [4]: Series.from_csv('/home/wesm/tmp/sfoo.csv')
Out[4]:
a 1
b 2
You can also pass `header=None, index_col=0, squeeze=True` to `read_csv` similar to what Rutger Kassies suggested.
Problem
I can't figure out how to write/read a Series correctly...The following (and many variations of it) results in the read series being different than the written series...note that the series is read into a DataFrame rather than a series. ``` In [55]: s = pd.Series({'a': 1, 'b': 2}) In [56]: s Out[56]: a 1 b 2 In [57]: s.to_csv('/tmp/s.csv') In [58]: !cat /tmp/s.csv a,1 b,2 In [59]: pd.read_csv('/tmp/s.csv') Out[59]: a 1 0 b 2 ```