【发布时间】:2017-06-29 18:40:20
【问题描述】:
我有一个包含 500,000 行的 dataframe1。我想通过在包含配置的 dataframe2 中查找型号来填充配置列。
数据框1:
Model Date Status Configuration
A4 10/2014 Inop
A4 11/2014 Op
A4 11/2014 Op
G5 10/2014 Inop
G5 11/2014 Inop
G5 11/2014 Op
G8 10/2014 Op
G8 11/2014 Op
G8 11/2014 Op
G8 10/2014 Inop
Z2 11/2014 Op
Z2 11/2014 Op
数据框2:
Model Configuration
A4 ICS
G5 PCS
G8 ICS
Z2 1/2 ICS
我目前正在运行的代码:
for Model, group in dataframe1.groupby('Model'):
#gets configuration from dataframe2
config = get_configuration(Model)
#attempt to assign configuration to all columns with that model number in dataframe1
dataframe1['Config'] = con
此代码返回:
此代码按模型对 dataframe1 进行分组并成功获取每个组的配置,但我无法将该配置应用于 dataframe1 中的新行以获得以下结果:
Model Date Status Configuration
A4 10/2014 Inop ICS
A4 11/2014 Op ICS
A4 11/2014 Op ICS
G5 10/2014 Inop PCS
G5 11/2014 Inop PCS
G5 11/2014 Op PCS
G8 10/2014 Op ICS
G8 11/2014 Op ICS
G8 11/2014 Op ICS
G8 10/2014 Inop ICS
Z2 11/2014 Op 1/2 ICS
Z2 11/2014 Op 1/2 ICS
【问题讨论】:
标签: python pandas dataframe jupyter