Uis234
Uis234

Reputation: 261

Converting DateTime format of Excel into DateTime Pandas

From a query executed with Microsoft SQL Server, I have exported a csv file i would like to load into a data frame with pandas. Here I have some columns which contain date time values. In Microsoft SQL the date time values are normally presented. However, when exported to csv, the date time values change to I think a float. Here is a sample:

        DateTime 1      Datetime 2   
        20/04/16 07:15  13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0
        15:00.0         13:00.0

In the first row you see the date time value that is behind the integer. It 'comes to light' when i enter the cell in excel and press enter... When i load this into pandas with read_csv, the 15:00.0 is loaded and not the 20/04/16 07:15.

I tried to change the column to datetime using xrld package of Python, unfortunately it did not have the expected output.

What kind of format is this exactly and is it possible to write code to automate the conversion of the datetime columns?

Upvotes: 0

Views: 2305

Answers (1)

shivsn
shivsn

Reputation: 7838

You should mention parse_dates=True or parse_dates=['column name'] when reading the file.

df = pd.read_csv('filename.csv',parse_dates=['column_name']

See Documentation for more information. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

Upvotes: 3

Related Questions