<?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: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27737#M19590</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Registered to post this so forgive the formatting nightmare&lt;/P&gt;
&lt;P&gt;This is a python databricks script function that allows you to convert from string to datetime or date and utilising coalesce&lt;/P&gt;from pyspark.sql.functions import coalesce, to_date
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;def to_datetime_(col, format): # Spark 2.2 or later syntax, for &amp;lt; 2.2 use unix_timestamp and cast return coalesce(to_date(col, format)) &lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;df3 = sqlContext.sql(sqlString2)df3.withColumn(df3['CalDay'],pd.to_datetime_(df3['CalDay'],format = '%Y%m%d'))
&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2019 06:06:21 GMT</pubDate>
    <dc:creator>JoshuaJames</dc:creator>
    <dc:date>2019-10-25T06:06:21Z</dc:date>
    <item>
      <title>Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27732#M19585</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I am trying to convert a dataframe column which is in the format of string to date type format yyyy-MM-DD?&lt;/P&gt;
&lt;P&gt;I have written a sql query and stored it in dataframe.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;df3 = sqlContext.sql(sqlString2)
df3.withColumn(df3['CalDay'],pd.to_datetime(df3['CalDay'],format = '%Y%m%d'))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get this error&lt;/P&gt;
&lt;P&gt;ValueError: Cannot convert column into bool: please use '&amp;amp;' for 'and', '|' for 'or', '~' for 'not' when building DataFrame boolean expressions.&lt;/P&gt;
&lt;P&gt;How is this happening?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 08:41:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27732#M19585</guid>
      <dc:creator>desai_n_3</dc:creator>
      <dc:date>2019-10-03T08:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27733#M19586</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi @desai.n.3, In scala please use coalesce function to convert Date format,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df.withColumn("Date", coalesce(
  to_timestamp($"Date", "yyyyMMdd"))).show&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 09:56:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27733#M19586</guid>
      <dc:creator>shyam_9</dc:creator>
      <dc:date>2019-10-03T09:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27734#M19587</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hi Thanks for the reply,&lt;/P&gt;
&lt;P&gt;It says coalesce fucntion not defined, plus gives invalid syntax with $&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 10:58:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27734#M19587</guid>
      <dc:creator>desai_n_3</dc:creator>
      <dc:date>2019-10-03T10:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27735#M19588</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using the Databricks notebook the above code works and for Pandas use below code,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df['Date']= pd.to_datetime(df['Date'])&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 15:12:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27735#M19588</guid>
      <dc:creator>shyam_9</dc:creator>
      <dc:date>2019-10-03T15:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27736#M19589</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You gave him scala code, his code is obviously python&lt;/P&gt;&lt;P&gt;&lt;/P&gt;"Databricks notebooks" can be python, scala even SQL so my advice is check the question and answer in the language they are using at least (both if you know it for future people) 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 05:56:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27736#M19589</guid>
      <dc:creator>JoshuaJames</dc:creator>
      <dc:date>2019-10-25T05:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27737#M19590</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Registered to post this so forgive the formatting nightmare&lt;/P&gt;
&lt;P&gt;This is a python databricks script function that allows you to convert from string to datetime or date and utilising coalesce&lt;/P&gt;from pyspark.sql.functions import coalesce, to_date
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;def to_datetime_(col, format): # Spark 2.2 or later syntax, for &amp;lt; 2.2 use unix_timestamp and cast return coalesce(to_date(col, format)) &lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;df3 = sqlContext.sql(sqlString2)df3.withColumn(df3['CalDay'],pd.to_datetime_(df3['CalDay'],format = '%Y%m%d'))
&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:06:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27737#M19590</guid>
      <dc:creator>JoshuaJames</dc:creator>
      <dc:date>2019-10-25T06:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Convert Column to Bool Error - When Converting dataframe column which is in string to date type in python</title>
      <link>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27738#M19591</link>
      <description>&lt;P&gt;the resulting comment is looking nothing like it does in edit mode&lt;/P&gt;&lt;P&gt;this is the function&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;def to_datetime_(col, format): 
# Spark 2.2 or later syntax, for &amp;lt; 2.2 use unix_timestamp and cast 
    return coalesce(to_date(col, format))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:08:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/cannot-convert-column-to-bool-error-when-converting-dataframe/m-p/27738#M19591</guid>
      <dc:creator>JoshuaJames</dc:creator>
      <dc:date>2019-10-25T06:08:23Z</dc:date>
    </item>
  </channel>
</rss>

