我正在尝试根据组ID逐行填充NaN值
我尝试过使用fillNA,使用forward和backward fill选项,但是fillNA函数不会逐行填充dataframe。另外,我要确保在填充NaN值之前公司匹配。在这种情况下,使用正向填充将导致公司“Pear”中填充来自公司“Banana”的数据。你知道吗
appended = appended.sort_values(by=['Company','Intro'],na_position='last')
appended = appended.reset_index(drop=True)
for i in appended.index:
if i==0:
pass
else:
if appended.at[i,'Company']==appended.at[i-1,'Company']:
appended.fillna(method='ffill',inplace=True)
else:
pass
附加数据帧
Company Intro Categories Headquarters Founded Date Funding Stage
Apple xyz Healthcare, Big Data New York 2018 Series A
Apple NaN NaN NaN NaN NaN
Apple NaN NaN NaN NaN NaN
Banana Lier Government Europe 2010 Series B
Pear NaN NaN NaN NaN NaN
这是我希望达到的预期结果:
Expected Result
Company Intro Categories Headquarters Founded Date Funding Stage
Apple xyz Healthcare, Big Data New York 2018 Series A
Apple xyz Healthcare, Big Data New York 2018 Series A
Apple xyz Healthcare, Big Data New York 2018 Series A
Banana Lier Government Europe 2010 Series B
Pear NaN NaN NaN NaN NaN
将^{} 与^{} 一起使用
相关问题 更多 >
编程相关推荐