我尝试按 order_id 分组并对金额求和,但 order_total 为 nan。 这是我的代码:
<!DOCTYPE html>
<html>
<script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
<script src="https://rawgit.com/jeromeetienne/ar.js/master/aframe/build/aframe-ar.js"></script>
<script>
AFRAME.registerComponent('clickhandler', {
init: function () {
this.el.addEventListener('click', () => {
this.el.setAttribute('material', 'color: red;');
});
},
});
</script>
<body>
<a-scene embedded arjs>
<a-marker cursor="rayOrigin: mouse;" preset="hiro">
<a-box
material="color: white;"
position="0 0 0"
depth="0.2"
height="0.01"
width="0.2"
clickhandler
/>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
</body>
</html>
test.csv:
import csv
import re
import json
import pandas as pd
df = pd.read_csv('test.csv',converters={'STORE_CODE': lambda x: str(x)})
df['Order_ID'] = df['STORE_CODE']+df['DOCUMENT_NUMBER']
df['Order_total'] = df.groupby(['Order_ID'])['NET_AMOUNT'].sum()
df.drop_duplicates(subset ="Order_ID",keep = "first", inplace = True)
print(df)
和我的结果:
STORE_CODE,DOCUMENT_NUMBER,NET_AMOUNT
4815,S21025748,67200.0
4815,S21025755,59200.0
4818,S21009748,16000.0
4818,S21009751,6000.0
4817,S21010032,-109000.0
4818,S21009746,138000.0
4822,S21015966,148000.0
4822,S21015965,38000.0
4818,S21009751,12000.0
4822,S21015969,127680.0
4826,S21008157,60000.0
4811,S21016408,89000.0
我不知道为什么我不能通过 order_id 对金额求和。 任何帮助将不胜感激。