Hi have data like below
JavaScript
x
11
11
1
Time qty
2
2021-07-23 02-06-49 0.02
3
2021-07-23 02-06-51 0.02
4
2021-07-23 02-06-53 2
5
2021-07-23 02-06-53 0.032
6
2021-07-23 02-06-54 2.842
7
2021-07-23 02-06-54 0.025
8
2021-07-23 02-06-55 0.02
9
2021-07-23 02-06-57 1.742
10
2021-07-23 02-06-57 0.395
11
JavaScript
1
4
1
df = pd.pivot_table(df,index=['Time'],values=['qty'],aggfunc=np.sum)
2
3
print(df)
4
result like below
JavaScript
1
8
1
Time qty
2
2021-07-23 02-06-49 0.02
3
2021-07-23 02-06-51 0.02
4
2021-07-23 02-06-53 2.000000000.03200000
5
2021-07-23 02-06-54 2.842000000.02500000
6
2021-07-23 02-06-55 0.02
7
2021-07-23 02-06-57 1.742000000.39500000
8
I want the sum of qty value
Advertisement
Answer
Based on the output, it seems to me that “qty” a “string” dtype. Try forcing it to be a “float” and try again:
JavaScript
1
3
1
df = df.astype({"qty": "float"})
2
df = pd.pivot_table(df, index=['Time'], values=['qty'], aggfunc=np.sum)
3