Reputation: 666
Initial dataframe:
data = [[1, 2, "qw"],
[2, 1, "er"],
[2, 2, "xy"],
[1, 2, np.nan],
[2, 2, np.nan]]
df = pd.DataFrame(data, columns = ["c1", "c2", "c3"])
What I'm looking for:
Upvotes: 0
Views: 217
Reputation: 446
In pandas there are more than one way of getting things done. Below is one of the ways. I used your definition of the dataframe above:
X = df[~df["c3"].isna()]
df = df.merge(X, how="left", on=["c1", "c2"])
df.drop("c3_x", axis=1, inplace=True)
df.rename(columns={"c3_y": "c3"}, inplace=True)
Basically merging the df with itself and getting rid of NAs. Cheers
Upvotes: 1