在一个包含大量数据的json文件中,我得到24列,每行包含700k行,其中一列内部有一个字典,因此我在下面选择了该列:
dataset = pd.read_json('ecommerce-events - Copia.json', lines=True)
dataset.loc[dataset['eventType']=="transaction"]
在交易栏中有“价格”,想将所有价格乘以数量,我如何用熊猫来做到这一点?
'url': 'da7caa77e2729e12b32a9d7d1a324652ce2264a6',
'referrer': '6e03ee62984224d0c0f08d4b68b819297d7f4d14',
'order': 5545, # unique transaction id
'orderItems': [{ # list of products bought in that transaction
'product': 16493, # product id
'price': 19.9, # product unit price
'quantity': 1.0
答案 0 :(得分:0)
def summation(x):
value=x["price"] * x["qun"]
return value
df = pd.DataFrame({“交易”:[[{“ price”:23,“ qun”:2}],[{“ price”:25,“ qun”:2}],[{“ price“:24,” qun“:2}]]}))
df [“ summation_value”] = df [[“” Transaction“]]。apply(lambda x:summation(x [0] [0]),axis = 1)