Skip to content
Advertisement

Fill Dataframe with values from another Dataframe (not the same column names)

I’m trying to fill a empty dataframe (OutputData) in Python with values from another dataframe (InputData).

InputData has four columns (“Strike”, “DTE”, “IV”, “Pred_IV”) OutputData has as an index all unique Strikes from InputData and as Column names all unique DTE from Input Data.

My goal is to fill the OutputData with the corresponding “Pred_IV” values from InputData. As it needs to match both the index and the column name I’m not getting my head around on how to do it with any known function.

If there is no value in InputData which matches both the index and column name the value can remain NaN

Find below the dataframes I use with the df.to_dict() extract for additional detail.

Many thanks for your help.

Best, Flo

InputData.head()

JavaScript

InputData.head().to_dict()

JavaScript

OutputData.head()

JavaScript

OutputData.head(2).to_dict()

JavaScript

Advertisement

Answer

Here is a way to do what I believe your question is asking:

JavaScript

Output:

JavaScript

If you prefer unnamed indexes, you can do this instead:

JavaScript

Output:

JavaScript
Advertisement