<?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 Re: issue with rounding selected column in &amp;quot;for in&amp;quot; loop in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28281#M20104</link>
    <description>&lt;P&gt;You're absolutely right. thanks&lt;/P&gt;</description>
    <pubDate>Mon, 14 Feb 2022 14:50:07 GMT</pubDate>
    <dc:creator>Braxx</dc:creator>
    <dc:date>2022-02-14T14:50:07Z</dc:date>
    <item>
      <title>issue with rounding selected column in "for in" loop</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28279#M20102</link>
      <description>&lt;P&gt;This must be trivial, but I must have missed something.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataframe (test1) and want to round all the columns listed in list of columns (col_list)&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/2082iC79207853369502A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;here is the code I am running:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;col_list = ['measure1', 'measure2', 'measure3']
&amp;nbsp;
for i in col_list:
  rounding = test1\
    .withColumn(i, round(col(i),0))
&amp;nbsp;
display(rounding)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and as a result only the last column has its values rounded.&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/2081iD1FBE219D0F0AB65/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;What am I missing to have all the measures rounded?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data for testing:&lt;/P&gt;&lt;P&gt;car	model	measure1	measure2	measure3&lt;/P&gt;&lt;P&gt;Nissan	aa	1.11	0.3	34&lt;/P&gt;&lt;P&gt;Toyota	bb	1.12	0.4	111&lt;/P&gt;&lt;P&gt;BMW	cc	1.13	0.5	1.9&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 10:40:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28279#M20102</guid>
      <dc:creator>Braxx</dc:creator>
      <dc:date>2022-02-14T10:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: issue with rounding selected column in "for in" loop</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28280#M20103</link>
      <description>&lt;P&gt;Because it's a for loop, and in the last loop column measure3 is selected. The variable rounding is assigned a new dataframe with changes that occur on column measure3 only.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;rounding = test1
for i in col_list:
  rounding = rounding\
    .withColumn(i, round(col(i),0))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 13:27:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28280#M20103</guid>
      <dc:creator>AmanSehgal</dc:creator>
      <dc:date>2022-02-14T13:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: issue with rounding selected column in "for in" loop</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28281#M20104</link>
      <description>&lt;P&gt;You're absolutely right. thanks&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 14:50:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-with-rounding-selected-column-in-quot-for-in-quot-loop/m-p/28281#M20104</guid>
      <dc:creator>Braxx</dc:creator>
      <dc:date>2022-02-14T14:50:07Z</dc:date>
    </item>
  </channel>
</rss>

