Chandra sekhar
Chandra sekhar

Reputation: 1

Date conversion in python pandas.read_excel

I have an excel file which has two columns column1 = "Jan-01" column2 = "2009"

I want to know how to build a converter/ any function that reads the above two columns and give me string as 01/01/2009 (Day/Month/Year)

enter image description here

Thanks in advance

Upvotes: 0

Views: 1439

Answers (1)

Shijith
Shijith

Reputation: 4872

you can read both columns as strings and the combine those and parse to date,for eg. if your excel file is

day&Month   Year    data
Jan-01      2009    1
Jan-02      2009    2
Jan-03      2009    3

assuming you have only one shhet on your excel file, do

df = pd.read_excel('path\yourexcel.xlsx',dtype={'day&Month':str,'Year':str},parse_dates={'Dates':[0,1]})
print(df)
  Dates          data
0 2009-01-01     1
1 2009-01-02     2
2 2009-01-03     3

Upvotes: 1

Related Questions