I need to write a pandas.Series object to a CSV file as a row, not as a column. Simply doing
the_series.to_csv( 'file.csv' )
gives me a file like this:
record_id,2013-02-07
column_a,7.0
column_b,5.0
column_c,6.0
What I need instead is this:
record_id,column_a,column_b,column_c
2013-02-07,7.0,5.0,6.0
This needs to work with pandas 0.10, so using the_series.to_frame().transpose() is not an option.
Is there a simple way to either transpose the Series, or otherwise get it written as a row?
Thanks!
You can just use the DataFrame constructor (rather than to_frame):
In [11]: pd.DataFrame(s).T
Out[11]: 
record_id   column_a  column_b  column_c
2013-02-07         7         5         6
                        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