【发布时间】:2019-02-11 02:14:25
【问题描述】:
我有一个字典商店,其中包含作为键的出口名称和作为其值的出口类型
stores = {'McDonalds':'Fast food','African and Eastern Beverage':'Alcohol','Baskin Robbins': 'ice Cream'}
我有一个 pandas 数据框,其中包含商店名称以及分支位置(在 Merchant 列中),其中一些具有 MerchantType 的 NaN 值
我需要填充具有 NaN 值的行的 MerchantType 列,并使用商店字典匹配商家类型,记住商店字典不包含位置(阿布扎比、迪拜、华盛顿等)在键中。
print (df)
Merchant MerchantType
index
0 McDonalds Abu Dhabi NaN
1 Dunkin Donuts Sweets
2 African and Eastern Beverage Dubai NaN
3 Burger King Fast Food
4 African and Eastern Beverage Abu Dhabi NaN
5 Burger King Fast Food
6 Baskin Robbins Washington NaN
完成这项工作最有效的方法是什么?
【问题讨论】:
标签: python pandas dataframe dictionary