Last active
February 17, 2020 17:40
-
-
Save nkushwah/a942c30d9f48db86e6db0bee8a676b75 to your computer and use it in GitHub Desktop.
forward fill example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df = pd.DataFrame([[1, 2, 3], [None, None, 6], [None, 9, None]]) | |
print(df) | |
''' | |
0 1 2 | |
0 1.0 2.0 3.0 | |
1 NaN NaN 6.0 | |
2 NaN 9.0 NaN | |
''' | |
df1 = df[1].fillna(method='ffill') | |
print(df1) | |
''' | |
0 1 2 | |
0 1.0 2.0 3.0 | |
1 NaN 2.0 6.0 | |
2 NaN 9.0 NaN | |
''' | |
df1 = df.fillna(method='ffill') | |
print(df1) | |
''' | |
0 1 2 | |
0 1.0 2.0 3.0 | |
1 1.0 2.0 6.0 | |
2 1.0 9.0 6.0 | |
''' | |
df[0].fillna(method='ffill',limit=1 , inplace=True) | |
print(df) | |
''' | |
0 1 2 | |
0 1.0 2.0 3.0 | |
1 1.0 NaN 6.0 | |
2 NaN 9.0 NaN | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment