<?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: PySpark column object not callable using &amp;quot;when otherwise&amp;quot; transformation in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12390#M7205</link>
    <description>&lt;P&gt;Hi @Karl Lacher​,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a friendly follow-up. Did the response from Werner's help? if it did, please mark it as best. Otherwise, please let us know if you still need help.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2022 20:56:58 GMT</pubDate>
    <dc:creator>jose_gonzalez</dc:creator>
    <dc:date>2022-08-17T20:56:58Z</dc:date>
    <item>
      <title>PySpark column object not callable using "when otherwise" transformation</title>
      <link>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12388#M7203</link>
      <description>&lt;P&gt;The very first "when" function results in the posted error message (see image). The print statement of the count of df_td_amm works. A printSchema of the "df_td_amm" data frame confirms that "AGE" is a column. A select statement is also successful, so wondering why the column isn't accessible in the "when" function. I've tried referencing the column df_td_amm.AGE and get the same error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried this on two other small dataframes not created using Pandas and encounter the same error. For two other multi-column dataframes, the "when" function works fine referencing the columns as expected.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import pandas as pd
import pyspark.sql
from pyspark.sql.functions import *
from pyspark.sql.types import *
&amp;nbsp;
months = list(range(26))
pdf = pd.DataFrame(months, columns = ['AGE'])
&amp;nbsp;
df_td_amm = spark.createDataFrame(pdf).cache()
print(df_td_amm.count())
&amp;nbsp;
df_age_bucket = df_td_amm \
                   .withColumn("COMPOUNDING_FREQ", \
                                   when(col("AGE") &amp;lt;= 3, "00-03 Months")
                                  .when(col("AGE") &amp;lt;= 6, "04-06 Months")
                                  .when(col("AGE") &amp;lt;= 9, "07-09 Months")
                                  .other("Other"))
&amp;nbsp;
display(df_age_bucket)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Error"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1680i7643616ACDBCBE3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Error" alt="Error" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 20:46:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12388#M7203</guid>
      <dc:creator>Karl</dc:creator>
      <dc:date>2022-07-26T20:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: PySpark column object not callable using "when otherwise" transformation</title>
      <link>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12389#M7204</link>
      <description>&lt;P&gt;the syntax is when(....).&lt;B&gt;otherwise&lt;/B&gt;(...), not other(...)&lt;/P&gt;&lt;P&gt;And there are some backslashes missing.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 11:22:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12389#M7204</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-07-27T11:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: PySpark column object not callable using "when otherwise" transformation</title>
      <link>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12390#M7205</link>
      <description>&lt;P&gt;Hi @Karl Lacher​,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a friendly follow-up. Did the response from Werner's help? if it did, please mark it as best. Otherwise, please let us know if you still need help.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 20:56:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pyspark-column-object-not-callable-using-quot-when-otherwise/m-p/12390#M7205</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2022-08-17T20:56:58Z</dc:date>
    </item>
  </channel>
</rss>

