0

I have a .csv file with one column containing the date using backslashes '/' to separate the month, day and year in one column. The following three columns contain a mean financial value, an upper financial value and a lower financial value. The data format look like the following example;

3/2/14  18338.98    18734.07    17943.88
3/3/14  18280.09    18675.2     17884.99
3/4/14  18220.26    18614.53    17825.98
3/5/14  18160.29    18551.71    17768.87

How can I get python to read in the date column and recognize it as a date in the format of month, day, year for eventual plotting with matlibplot?

Jon
  • 1,621
  • 5
  • 23
  • 46
  • Possible duplicate of [plotting time in python with matplotlib](http://stackoverflow.com/q/1574088/2823755). – wwii Feb 20 '15 at 05:47

1 Answers1

1

Use the datetime module to create a datetime object

>>> import datetime
>>> dt = datetime.datetime.strptime('3/5/14', '%m/%d/%y')
>>> dt
datetime.datetime(2014, 3, 5, 0, 0)

Use the strftime method to create labels for the axis ticks.

>>> dt.strftime('%d%b%Y')
'05Mar2014'
>>> 
wwii
  • 23,232
  • 7
  • 37
  • 77