Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have DataFrame which looks like this -

  37 days 19:07:00

  69 days 02:32:00

  44 days 00:38:00

  14 days 07:30:00

  14 days 23:03:00

  41 days 16:41:00

I want to convert this time into months for which I am using this code -

df_new['difference'] = df_new['time'].dt.total_seconds().div(60).astype(int)

This is giving me results but for days less then 30 it is returning me 0 months so I want a decimal value of this column instead of absolute number. How can I do that? My ultimate goal is to find mean of this column.

My current output looks like column one and my desired output is in column 2.

Current 

1

2

2

5

0

0

Desired 

1

2

2

5

0.2

0.5

1 Answer

0 votes
by (41.4k points)

Change astype(int) to astype(float)

df_new['difference'] = df_new['time'].dt.total_seconds().div(60).astype(float)

Browse Categories

...