标签:none cal port lse .data 聚合 one 问题 gre
pandas.core.base.DataError: No numeric types to aggregate错误规避
我没有去解决这个问题, 而用填充0规避了这个问题
d = [
{'cur': 1, 'next': 2, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 3, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 4, 'avgtime': None, 'callcount': None},
{'cur': 1, 'next': 2, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 3, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 4, 'avgtime': None, 'callcount': None},
{'cur': None, 'next': 4, 'avgtime': None, 'callcount': None},
]
df = pd.DataFrame(d, dtype='int')
df.groupby(["cur", "next"], as_index=False).mean()
使用这种聚合会卡到这个bug
pandas.core.base.DataError: No numeric types to aggregate错误规避
import pandas as pd
d = [
{'cur': 1, 'next': 2, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 3, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 4, 'avgtime': None, 'callcount': None},
{'cur': 1, 'next': 2, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 3, 'avgtime': None, 'callcount': None},
{'cur': 2, 'next': 4, 'avgtime': None, 'callcount': None},
{'cur': None, 'next': 4, 'avgtime': None, 'callcount': None},
]
df = pd.DataFrame(d, dtype='int')
g = df.groupby(["cur", "next"], as_index=False)
res = g.agg(
{
'avgtime': 'sum',
'callcount': 'mean',
}
)
标签:none cal port lse .data 聚合 one 问题 gre
原文地址:https://www.cnblogs.com/iiiiiher/p/10218994.html