我想按组ID逐行填充NaN值,已尝试使用fillNA函数,并使用向前和向后填充选项,但fillNA函数未逐行填充数据框。此外,在填充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