To substitute missing data with corresponding values from another dataframe, you could use the fillna
method along with the other
parameter. Here's an example:
import pandas as pd df1 = pd.DataFrame({'A': [1, 2, 3, None, 5], 'B': [6, None, 8, 9, 10]}) df2 = pd.DataFrame({'A': [11, 12, 13, 14, 15], 'B': [16, 17, 18, 19, 20]}) filled_df = df1.fillna(df2) print(filled_df)
In this example, df1
is the dataframe containing the missing values and df2
is the dataframe with the corresponding values. The fillna
method is then used to fill in the missing values in df1
with the corresponding values from df2
. The resulting dataframe (filled_df
) will contain all the values from df1
, except the missing ones will be filled in with the corresponding values from df2
.
Asked: 2022-11-08 11:00:00 +0000
Seen: 10 times
Last updated: Aug 10 '21