2017-02-16 28 views
1

上的數據幀的產率輸出否則res = ans.groupby(['Unique_Inventor_Number_x', 'AppYearStr_x']).Citation.nunique()的最接近的值作爲填充一個數據幀的空單元與前述細胞

Unique_Inventor_Number_x AppYearStr_x 
2.0      1987.0   1 
5.0      1977.0   1 
6.0      1977.0   1 
          1987.0   1 
          1993.0   4 
7.0      1990.0   1 
          1994.0   10 
          1996.0   6 
          1998.0   6 
          1999.0   4 
9.0      1979.0   1 

如所看到的,而不是在所有Unique_Inventor_Number_x細胞被填充。我想填充所有這些細胞與前述整數這樣的:

Unique_Inventor_Number_x AppYearStr_x 
2.0      1987.0   1 
5.0      1977.0   1 
6.0      1977.0   1 
6.0      1987.0   1 
6.0      1993.0   4 
7.0      1990.0   1 
7.0      1994.0   10 
7.0      1996.0   6 
7.0      1998.0   6 
7.0      1999.0   4 
9.0      1979.0   1 

什麼是快捷方式大熊貓做到這一點?

+0

你試過df.fillna(method ='ffill')? – Vaishali

回答

1

你想使用fillna方法與kwarg method='ffill'。這將向前傳播空值。

編輯 我看到您正在使用groupby並希望刪除索引中的空值。你可以這樣做:

res.reset_index().set_index('Unique_Inventor_Number_x')