给定数据帧df1
,如下所示:
要拆分industry_keywords
列,我使用df1['industry_keywords'].str.split(',', expand=True)
输出:
0 1
0 Chemicals Electrical Equipment
1 Information Technology Software & Services
2 Tobacco Beverages
3 Pharmaceuticals Health Care
4 Technology None
5 Oil and Gas Energy
6 Technology Food Products
7 Manufacturing None
df2:
我想把{
预期结果如下:
company_name ... label
0 Looney Tunes ... second tiers, second tiers
1 The Simpsons ... third tiers
2 Soylent Green ... first tiers
3 Initech ... NaN
4 Resident Evil ... third tiers
5 Hooli ... second tiers
6 Weeds ... third tiers, first tiers
7 Fringe ... second tiers
我怎么能这么做?也许我应该为df2
创建一个dictionary
文件?谢谢
首先将^{} 与^{} 一起使用,然后使用convert index to column合并以避免丢失值,通过
join
聚合并添加到原始df1
:要删除重复项,请使用^{} :
相关问题 更多 >
编程相关推荐