0

I am trying to convert some of my data within a column of my Pandas data frame from the date format i.e 04-Jan to the int format i.e 4-1.

This is what the data in the column currently looks like.

0 04-Jan 1 0 - 5 2 01-Jan 3 3 - 0 4 0 - 0 5 0 - 3 6 03-Jan 7 0 - 0 8 0 - 1 9 4 - 0 10 02-Jan 11 01-Feb 12 01-Jan 13 1 - 0 14 03-Jan

And this is what I am trying to achieve.

0 4 - 1 1 0 - 5 2 1 - 1 3 3 - 0 4 0 - 0 5 0 - 3 6 3 - 1 7 0 - 0 8 0 - 1 9 4 - 0 10 2 - 1 11 1 - 2 12 1 - 1 13 1 - 0 14 3 - 1

I have tried using the DateTime module to covert it initially from 04-jan to 04-01 but was unsuccessful and I've also tried the str.split method but that is only splitting the data in the rows with integers.

Sj293
  • 51
  • 4
  • Have you read any tutorials on this topic? Have you tried any methods they suggest there or here on SO? If so, which and why didn't they work? – Mr. T Dec 20 '20 at 16:11
  • 1
    the pandas docs are also very good, have a look at [pandas.to_datetime](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html). you can cast your data to datetime using `format="%d-%b"` and then extract month and day. – FObersteiner Dec 20 '20 at 16:20
  • Please share sample input with expected output for better understanding. Without that the question is likely to be downvoted and closed. – Mayank Porwal Dec 20 '20 at 17:25

0 Answers0