Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
Showing results for 
Search instead for 
Did you mean: 

Append an empty dataframe to a list of dataframes using for loop in python

New Contributor II

I have the following 3 dataframes:

imageI want to append df_forecast to each of df2_CA and df2_USA using a for-loop. However when I run my code, df_forecast is not appending: df2_CA and df2_USA appear exactly as shown above.

Here’s the code:

df_list=[df2_CA, df2_USA] 
for x in df_list:
     pd.concat([x, df_forecast]) 
     x.loc['2020-03':'2020-05', 'rev'] = 200

And here is the desired result:

imageWhat's wrong with my code?


Honored Contributor

@Jack Homareau​  Can you try union functionality with dataframes?

and then try to fill NaNs with the desired values?

Community Manager
Community Manager

Hi @Jack Homareau​ , We haven’t heard from you on the last response from @Arvind Ravish​ , and I was checking back to see if you have a resolution yet. If you have any solution, please do share that with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!