Description
pandas version: 0.11
python version: 2.7.4
platforms: linux & windows
When using cols parameter of to_csv() method only the order of the header is changed, while actual values are not.
import pandas as pd
from cStringIO import StringIO
data = """\
date,time,X1,X2
2013-1-1,0030,0.1,0.4
2013-1-1,0100,0.2,0.3
2013-1-1,0130,0.3,0.2
2013-1-1,0200,0.4,0.1
"""
df = pd.read_csv(StringIO(data), parse_dates=[['date', 'time']], index_col=0)
df.to_csv('data.csv', index_label='date_time', cols=['X2', 'X1'])
Expected output:
date_time,X2,X1
2013-01-01 00:30:00,0.4,0.1
2013-01-01 01:00:00,0.3,0.2
2013-01-01 01:30:00,0.2,0.3
2013-01-01 02:00:00,0.1,0.4
Actual output:
date_time,X2,X1
2013-01-01 00:30:00,0.1,0.4
2013-01-01 01:00:00,0.2,0.3
2013-01-01 01:30:00,0.3,0.2
2013-01-01 02:00:00,0.4,0.1
df.to_csv('data.csv', index_label='date_time', cols=['X2'])
date_time,X2
2013-01-01 00:30:00,0.1
2013-01-01 01:00:00,0.2
2013-01-01 01:30:00,0.3
2013-01-01 02:00:00,0.4
print df['X1']
date_time
2013-01-01 00:30:00 0.1
2013-01-01 01:00:00 0.2
2013-01-01 01:30:00 0.3
2013-01-01 02:00:00 0.4
Name: X1, dtype: float64
print df['X2']
date_time
2013-01-01 00:30:00 0.4
2013-01-01 01:00:00 0.3
2013-01-01 01:30:00 0.2
2013-01-01 02:00:00 0.1
Name: X2, dtype: float64