There is a case am working since 2 days to solve the following issue:
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()
while I do this: I get the following error
File "<ipython-input-44-1a6629fd9584>", line 1 df360[(df360.claim_date <= str(end_Date)) & (df360.claim_date >= str(start_Date))['claim_amount'].sum() ^ SyntaxError: unexpected EOF while parsing
Fix your code with .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()
end_Date = "1st October, 2018"
end_Date = pd.to_datetime(end_Date)
start_Date = end_Date - pd.Timedelta(days = 20)
Then:
df360['claim_amount'].dtypes
See whether you get this as output:
dtype('float64')
and not:
dtype('o')
then paste this code:
df360[(df360.claim_date <= end_Date) & (df360.claim_date >= start_Date)]['claim_amount'].sum()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.