Python: Convert timedelta to int in a dataframe
问题 I would like to create a column in a pandas data frame that is an integer representation of the number of days in a timedelta column. Is it possible to use \'datetime.days\' or do I need to do something more manual? timedelta column 7 days, 23:29:00 day integer column 7 回答1: Use the dt.days attribute. Supposing td is the name of your timedelta Series, access this attribute via: td.dt.days You can also get the seconds and microseconds attributes in the same way. 回答2: You could do this, where