dirkvbok
dirkvbok

Reputation: 11

Is there a way to convert timedelta to pandas freq string?

You can do pd.to_timedelta('30min') to get a timedelta object of 30 minutes. Is there a similar way to go from a timedelta object to the freq string (like '30min', '1H', etc.)?

Upvotes: 1

Views: 1412

Answers (1)

joe
joe

Reputation: 31

you can create a pd.DateOffset and use its freqstr attribute:

import pandas as pd
from pandas.tseries.frequencies import to_offset
offset = to_offset(pd.Timedelta('30min'))
print(offset.freqstr)
# 30T

Upvotes: 3

Related Questions