在网上搜索,我发现pandas在这种情况下是有帮助的。我遵循了Convert CSV Data to Nested JSON in Python中给出的appraoch,但是我得到了一个keyError exception KeyError: 'state/site-packages/pandas/core/groupby/groupby.py", line 2110, in groupby
我似乎无法打印以下行:summarydata["Name"].groupby(["Tag"]).size() File "C:\Users\rspatel\untitled0.py"\Anaconda3\lib\site-packages\pandas\core\series.py", line 1720, in groupby
return SeriesGroupBy(File "C:\Users\rspatel\Anaconda3
_selected_obj)
File "/home/dan/.local/lib/python3.10/site-packages/pandas/core/groupby/groupby.py",/site-packages/pandas/core/groupby/groupby.py", line 88
这是我尝试过的代码,但我得到的是KeyError: 11 df = pd.DataFrame(data=np.random.rand(101, 3), columns=list('ABC'))for i, g in groups:
g.to_excel("%s.xlsx" % i, index = False参考相关:Split pandas dataframe into multi
For column-specific groupby renaming, use named aggregation
green 7000 7000
# Named aggregation throws a KeyErrorFile "C:\Users\AppData\Local\Continuum\anaconda3\Lib\
我可以用groupby做到这一点:df.groupby(['type', 'location']).mean().round(2) Out:
typeaverage based on condition into new column 并尝试将一些可能的解决方案应用到我的问题中: for atype, alocation in df.groupby_engine.get_loc(key)
2658 except <e