我正在尝试削减每个国家/地区的浮动值,同时按大陆对它们进行分组。 这是我写的代码:
groups = renew.groupby(['Continent'],pd.cut(renew['% Renewable'], 5))
我收到此错误
TypeError: can only concatenate str (not "float") to str
我不明白它试图在哪里连接,但我试图将“% Renewable”列中的值分成 5 个容器。
很难说为什么在没有看到数据的情况下会发生该特定错误,但首先将要分组的所有变量放在第一个参数中,例如
groups = renew.groupby(['Continent', pd.cut(renew['% Renewable'], 5)])