<?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 TypeError : withcolumn() takes 3 positional arguments but 4 were given. in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/45572#M27933</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Can some one please help me with the error.&lt;/P&gt;&lt;P&gt;This is my small python code.&lt;/P&gt;&lt;P&gt;binmaster = binmasterdf.withColumnRenamed("tag_number","BinKey")\&lt;/P&gt;&lt;P&gt;.withColumn ("Category", when (length("Bin")==4,'SMALL LOT'),(length("Bin")==7,'RACKING'))&lt;/P&gt;&lt;P&gt;TypeError : withcolumn() takes 3 positional arguments but 4 were given.&lt;/P&gt;&lt;P&gt;If I remove this&amp;nbsp;(length("Bin")==7,'RACKING'), there are no issues.&lt;/P&gt;&lt;P&gt;Can some one please let me know how to fix the error?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
    <pubDate>Thu, 21 Sep 2023 18:48:56 GMT</pubDate>
    <dc:creator>JohnJustus</dc:creator>
    <dc:date>2023-09-21T18:48:56Z</dc:date>
    <item>
      <title>TypeError : withcolumn() takes 3 positional arguments but 4 were given.</title>
      <link>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/45572#M27933</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Can some one please help me with the error.&lt;/P&gt;&lt;P&gt;This is my small python code.&lt;/P&gt;&lt;P&gt;binmaster = binmasterdf.withColumnRenamed("tag_number","BinKey")\&lt;/P&gt;&lt;P&gt;.withColumn ("Category", when (length("Bin")==4,'SMALL LOT'),(length("Bin")==7,'RACKING'))&lt;/P&gt;&lt;P&gt;TypeError : withcolumn() takes 3 positional arguments but 4 were given.&lt;/P&gt;&lt;P&gt;If I remove this&amp;nbsp;(length("Bin")==7,'RACKING'), there are no issues.&lt;/P&gt;&lt;P&gt;Can some one please let me know how to fix the error?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 18:48:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/45572#M27933</guid>
      <dc:creator>JohnJustus</dc:creator>
      <dc:date>2023-09-21T18:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: TypeError : withcolumn() takes 3 positional arguments but 4 were given.</title>
      <link>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/45683#M27968</link>
      <description>&lt;P&gt;Thanks for your response&lt;/P&gt;&lt;P&gt;Actually, here is my code with when function but I still see the error&lt;/P&gt;&lt;P&gt;binmaster = binmasterdf.withColumnRenamed("tag_number","BinKey")\&lt;/P&gt;&lt;P&gt;.withColumn ("Category", when (length("Bin")==4,'SMALL LOT'), when (length("Bin")==7,'RACKING'), otherwise('FLOOR'))&lt;/P&gt;&lt;P&gt;Is there anything wrong with the above?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 14:25:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/45683#M27968</guid>
      <dc:creator>JohnJustus</dc:creator>
      <dc:date>2023-09-22T14:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: TypeError : withcolumn() takes 3 positional arguments but 4 were given.</title>
      <link>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/46276#M28032</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/89587"&gt;@JohnJustus&lt;/a&gt;&amp;nbsp;If you see closely in&amp;nbsp;&lt;SPAN&gt;.withColumn ("Category", when (length("Bin")==4,'SMALL LOT'), when (length("Bin")==7,'RACKING'), otherwise('FLOOR')), withcolumn would take 2 parameters. The first parameter as a string and the second as the column. However in your code, you are passing 3 parameters i.e. first is string and the other two are when conditions so the last when condition is being considered as an extra parameter in withcolumn function. This is the reason removing last when is resolving the issue.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 11:22:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/46276#M28032</guid>
      <dc:creator>Noopur_Nigam</dc:creator>
      <dc:date>2023-09-26T11:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: TypeError : withcolumn() takes 3 positional arguments but 4 were given.</title>
      <link>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/46287#M28034</link>
      <description>&lt;P&gt;Thank you Noopur for your response.&lt;/P&gt;&lt;P&gt;So how can I accomplish with more than 2 parameters? Are there any other function available?&lt;/P&gt;&lt;P&gt;In this case, I have to check length multiple times and categorize them accordingly.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:25:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/typeerror-withcolumn-takes-3-positional-arguments-but-4-were/m-p/46287#M28034</guid>
      <dc:creator>JohnJustus</dc:creator>
      <dc:date>2023-09-26T14:25:12Z</dc:date>
    </item>
  </channel>
</rss>

