Python ProgrammingPython Programming

How to Import CSV to pandas with specific Index?

Import CSV with specific Index:

import pandas as pd

df = pd.read_csv('test.csv', index_col="DateTime")
print(df)


C:\pandas>python example.py
             Wheat    Rice     Oil
DateTime
10/10/2016  10.500  12.500  16.500
10/11/2016  11.250  12.750  17.150
10/12/2016  10.000  13.150  15.500
10/13/2016  12.000  14.500  16.100
10/14/2016  13.000  14.825  15.600
10/15/2016  13.075  15.465  15.315
10/16/2016  13.650  16.105  15.030
10/17/2016  14.225  16.745  14.745
10/18/2016  14.800  17.385  14.460
10/19/2016  15.375  18.025  14.175
 
C:\pandas>