0
我的国家和人民的字典:为什么我得到大熊猫一系列的应用/分配函数内部
population_dict = {"Germany": 1111, .... }
在我的DF(sort_countries)我有一栏叫国家,我要添加叫从上面的字典人口另一个柱(用人口匹配国家)
population_df = sort_countries.assign(
population=lambda x: population_dict[x["country"]], axis = 1)
population_df.head()
这给错误:TypeError: 'Series' objects are mutable, thus they cannot be hashed
。
为什么x["country"]
系列,当我想象它应该只返回国家的名称。
这一点熊猫总是困惑我。在我的lambda中,我期望x是一排,我只是从那一行中选择国家。相反,len(x [“country”))给了我192(我的国家数量,整个系列)。
我怎么能匹配他们使用lambdas而不是一个单独的功能? 谢谢!
地图一个完美的作品。但.item()没有。我相信x [“country”]是整个专栏的一个系列。不明白为什么。我只需要那个特定的行... –