Python四舍五入日期

Python四舍五入日期,python,pandas,rounding,Python,Pandas,Rounding,当我运行以下代码时 import pandas as pd import numpy as np Master_Revenue_Schedule = 'Master Revenue Schedule.xlsx' df_Master_Revenue_Schedule = pd.read_excel(Master_Revenue_Schedule) #print(df_Master_Revenue_Schedule.columns) df_Coverage_End_Date = df_Mast

当我运行以下代码时

import pandas as pd
import numpy as np


Master_Revenue_Schedule = 'Master Revenue Schedule.xlsx'
df_Master_Revenue_Schedule = pd.read_excel(Master_Revenue_Schedule)
#print(df_Master_Revenue_Schedule.columns)

df_Coverage_End_Date = df_Master_Revenue_Schedule['coverage_end_date']
df_Coverage_Start_Date = df_Master_Revenue_Schedule['coverage_start_date']

Months_Calc = (df_Coverage_End_Date - df_Coverage_Start_Date)/(365.25/12)
print(Months_Calc)
我得到如下结果

0                        NaT
1                        NaT
2                        NaT
3                        NaT
4    11 days 23:00:51.745379
               ...
90   13 days 23:54:05.174537
91                       NaT
92   12 days 22:40:09.856262
93   15 days 23:12:41.396303
94   11 days 23:00:51.745379
df_Coverage_End_Date and df_Coverage_Start_Date both contain dates
我想把产量四舍五入。我试过下面的代码,但没有成功

Rounded_Months_Calc = round(Months_Calc,1)
print(Rounded_Months_Calc)

Python没有数据帧。如果您使用的是Pandas,请记住使用标签。您正在尝试舍入到整秒吗?@ScottBoston,我正在尝试舍入到整天。您可以从每列中取前2个字符,Months\u Calc=Months\u Calc.astype(str).str[:2]谢谢,但第一个值是11.98,我希望该值产生12。