从2天开始,有一个案例正在解决以下问题:

end_Date = "1st October, 2018"
end_Date = pd.to_datetime(end_Date)
start_Date = end_Date - pd.Timedelta(days = 20)

df360[(df360.claim_date <= str(end_Date)) & (df360.claim_date >= str(start_Date))['claim_amount'].sum()


当我这样做时:
我收到以下错误


  文件“ ”,第1行
      df360 [(df360.claim_date = str(开始日期))['claim_amount']。sum()
                                                                                                             ^
  SyntaxError:解析时出现意外的EOF

最佳答案

使用.loc修复代码

df360.claim_date = pd.to_datetime(df360.claim_date)
df360.loc[(df360.claim_date <= end_Date) & (df360.claim_date >= start_Date),'claim_amount'].sum()

关于python - 2018年10月1日(“ Pandas ”)之前的20天,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59019967/

10-12 17:01