<?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 New to PySpark in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64389#M6857</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to get the domain from an email field using below expression; but getting an error.&lt;/P&gt;&lt;P&gt;Kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df.select(df.email, substring(df.email,instr(df.email,'@'),length(df.email).alias('domain')))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 22 Mar 2024 11:08:09 GMT</pubDate>
    <dc:creator>Anku_</dc:creator>
    <dc:date>2024-03-22T11:08:09Z</dc:date>
    <item>
      <title>New to PySpark</title>
      <link>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64389#M6857</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to get the domain from an email field using below expression; but getting an error.&lt;/P&gt;&lt;P&gt;Kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df.select(df.email, substring(df.email,instr(df.email,'@'),length(df.email).alias('domain')))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 22 Mar 2024 11:08:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64389#M6857</guid>
      <dc:creator>Anku_</dc:creator>
      <dc:date>2024-03-22T11:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: New to PySpark</title>
      <link>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64391#M6858</link>
      <description>&lt;P&gt;Note: I have also tried:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;df.select(df.email, substring(df.email,instr(df.email,&lt;/SPAN&gt;&lt;SPAN&gt;'@'&lt;/SPAN&gt;&lt;SPAN&gt;)+&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;,length(df.email) - instr(df.email,&lt;/SPAN&gt;&lt;SPAN&gt;'@'&lt;/SPAN&gt;&lt;SPAN&gt;)+&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;).alias(&lt;/SPAN&gt;&lt;SPAN&gt;'domain'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 22 Mar 2024 11:18:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64391#M6858</guid>
      <dc:creator>Anku_</dc:creator>
      <dc:date>2024-03-22T11:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: New to PySpark</title>
      <link>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64446#M6859</link>
      <description>&lt;P&gt;In your case, you want to extract the domain from the email, which starts from the position just after '@'. So, you should add 1 to the position of '@'. Also, the length of the substring should be the difference between the total length of the email and the position of '@'.&lt;/P&gt;
&lt;P&gt;Can you try with the below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="_1t7bu9hb markdown-code-python hljs language-csharp" data-highlighted="yes"&gt;&lt;SPAN class="hljs-keyword"&gt;from&lt;/SPAN&gt; pyspark.sql.functions import instr, length, substring

df.&lt;SPAN class="hljs-keyword"&gt;select&lt;/SPAN&gt;(df.email, substring(df.email, instr(df.email, &lt;SPAN class="hljs-string"&gt;'@'&lt;/SPAN&gt;) + &lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;, length(df.email) - instr(df.email, &lt;SPAN class="hljs-string"&gt;'@'&lt;/SPAN&gt;)).&lt;SPAN class="hljs-keyword"&gt;alias&lt;/SPAN&gt;(&lt;SPAN class="hljs-string"&gt;'domain'&lt;/SPAN&gt;))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;This code will create a new column 'domain' that contains the domain of the email.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2024 16:09:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/new-to-pyspark/m-p/64446#M6859</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-03-23T16:09:39Z</dc:date>
    </item>
  </channel>
</rss>

