Home > OS >  How to change days format to total second in pandas data frame?
How to change days format to total second in pandas data frame?

Time:02-20

[1

This day format 17 days 00:00:00 To Format in seconds : 1641600.0 please tell the syntax for this pandas dataframe

CodePudding user response:

You can use pd.Timedelta and .view methods:

import numpy as np
import pandas as pd

# Create a sample dataframe
df = pd.DataFrame([{'delta_days':'17 days 00:00:00'}, {'delta_days':'19 days 00:00:00'}])

# Convert to the format of seconds
df['converted_delta_days'] = df['delta_days'].apply(lambda e: pd.Timedelta(e).view(np.int64) / 1e9)
delta_days converted_delta_days
0 17 days 00:00:00 1468800.0
1 19 days 00:00:00 1641600.0

CodePudding user response:

you have 23769 days in your first input of avgdelay column 23769 days means 76 years. please check your codes once again . delay must not be that much high. btw welcome to highradius doubt clearing session lol

  • Related