Ask Your Question
3

How can I substitute the missing data with corresponding values from another dataframe?

asked 2022-11-08 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-10 10:00:00 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-11-08 11:00:00 +0000

Seen: 10 times

Last updated: Aug 10 '21