我有这个问题:
import pandas as pd
stripline = "----------------------------"
rawData = {
'order number': ['11xa', '11xa', '11xa', '21xb', '31xc'],
'working area': ['LLA', 'LLE', 'LLS', 'MLA', 'MLE'],
'time': [1, 6, 13, 35, 24]
}
df = pd.DataFrame(rawData)
print("original data:")
print(df.head())
print(stripline)
rawData2 = {
'order number': ['11xa', '21xb', '31xc'],
'working area': ['LLS', 'MLA', 'MLE'],
'time': [20, 35, 24]
}
df2 = pd.DataFrame(rawData2)
print("expected result:")
print("group after order number, sum all times to that order and choose working field with the biggest time")
print(df2.head())
如何操作我的数据框 df 以获得 df2?
我想总结时间列中与订单号对应的所有值。我想使用时间最长的工作字段,特别是我想保留其余的数据。新的数据框有 3 个订单,旧的有 5 个。
catspeake
胡子哥哥
相关分类