Python Pandas - Date Column to Column index
dataframe, pandas, python
Solution
You can use `set_index`:
df.set_index('month')
For example:
In [1]: df = pd.DataFrame([[1, datetime(2011,1,1)], [2, datetime(2011,1,2)]], columns=['a', 'b'])
In [2]: df
Out[2]:
a b
0 1 2011-01-01 00:00:00
1 2 2011-01-02 00:00:00
In [3]: df.set_index('b')
Out[3]:
a
b
2011-01-01 1
2011-01-02 2
Problem
I have a table of data imported from a CSV file into a DataFrame. The data contains around 10 categorical fields, 1 month column (in date time format) and the rest are data series. How do I convert the date column into an index across the the column axis?