<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Append an empty dataframe to a list of dataframes using for loop in python in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/append-an-empty-dataframe-to-a-list-of-dataframes-using-for-loop/m-p/18915#M12610</link>
    <description>&lt;P&gt;I have the following 3 dataframes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1805i7A5E0966264F683D/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;I want to&amp;nbsp;&lt;B&gt;append df_forecast to each of df2_CA and df2_USA using a for-loop&lt;/B&gt;. However when I run my code,&amp;nbsp;&lt;B&gt;df_forecast is not appending&lt;/B&gt;: df2_CA and df2_USA appear exactly as shown above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here’s the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df_list=[df2_CA, df2_USA]&amp;nbsp;
&amp;nbsp;
for x in df_list:
&amp;nbsp;    pd.concat([x, df_forecast]) 
&amp;nbsp;    x['prod'].fillna(method='ffill',inplace=True)     
&amp;nbsp;    x['country'].fillna(method='ffill',inplace=True)
&amp;nbsp;    x.loc['2020-03':'2020-05', 'rev'] = 200&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is the desired result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1814i18D3BE03D9A9F61D/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;What's wrong with my code?&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 14:44:33 GMT</pubDate>
    <dc:creator>Jack</dc:creator>
    <dc:date>2022-06-02T14:44:33Z</dc:date>
    <item>
      <title>Append an empty dataframe to a list of dataframes using for loop in python</title>
      <link>https://community.databricks.com/t5/data-engineering/append-an-empty-dataframe-to-a-list-of-dataframes-using-for-loop/m-p/18915#M12610</link>
      <description>&lt;P&gt;I have the following 3 dataframes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1805i7A5E0966264F683D/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;I want to&amp;nbsp;&lt;B&gt;append df_forecast to each of df2_CA and df2_USA using a for-loop&lt;/B&gt;. However when I run my code,&amp;nbsp;&lt;B&gt;df_forecast is not appending&lt;/B&gt;: df2_CA and df2_USA appear exactly as shown above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here’s the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df_list=[df2_CA, df2_USA]&amp;nbsp;
&amp;nbsp;
for x in df_list:
&amp;nbsp;    pd.concat([x, df_forecast]) 
&amp;nbsp;    x['prod'].fillna(method='ffill',inplace=True)     
&amp;nbsp;    x['country'].fillna(method='ffill',inplace=True)
&amp;nbsp;    x.loc['2020-03':'2020-05', 'rev'] = 200&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is the desired result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1814i18D3BE03D9A9F61D/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;What's wrong with my code?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 14:44:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/append-an-empty-dataframe-to-a-list-of-dataframes-using-for-loop/m-p/18915#M12610</guid>
      <dc:creator>Jack</dc:creator>
      <dc:date>2022-06-02T14:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Append an empty dataframe to a list of dataframes using for loop in python</title>
      <link>https://community.databricks.com/t5/data-engineering/append-an-empty-dataframe-to-a-list-of-dataframes-using-for-loop/m-p/18916#M12611</link>
      <description>&lt;P&gt;@Jack Homareau​&amp;nbsp; Can you try union functionality with dataframes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sparkbyexamples.com/pyspark/pyspark-union-and-unionall/" target="test_blank"&gt;https://sparkbyexamples.com/pyspark/pyspark-union-and-unionall/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then try to fill NaNs with the desired values?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 04:36:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/append-an-empty-dataframe-to-a-list-of-dataframes-using-for-loop/m-p/18916#M12611</guid>
      <dc:creator>User16764241763</dc:creator>
      <dc:date>2022-06-06T04:36:22Z</dc:date>
    </item>
  </channel>
</rss>

