<?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 Length Value of a column in pyspark in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/length-value-of-a-column-in-pyspark/m-p/27747#M19595</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;i am using pyspark 2.12&lt;/P&gt;
&lt;P&gt;After Creating Dataframe can we measure the length value for each row.&lt;/P&gt;
&lt;P&gt;For Example: I am measuring length of a value in column 2&lt;/P&gt;
&lt;P&gt;Input file &lt;/P&gt;
&lt;P&gt;|TYCO|1303| &lt;/P&gt;
&lt;P&gt;|EMC |120989| &lt;/P&gt;
&lt;P&gt;|VOLVO|102329|&lt;/P&gt;
&lt;P&gt; |BMW|130157|&lt;/P&gt;
&lt;P&gt; |FORD|004| &lt;/P&gt;
&lt;P&gt;Output in Dataframe i am trying to get like&lt;/P&gt;
&lt;P&gt;|TYCO|1303|4&lt;/P&gt;
&lt;P&gt;|EMC |120989|6&lt;/P&gt;
&lt;P&gt;|VOLVO|1023295|7&lt;/P&gt;
&lt;P&gt;|BMW|130157|6&lt;/P&gt;
&lt;P&gt;|FORD|004| 3&lt;/P&gt;
&lt;P&gt;Please suggest if it is possible.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2019 18:03:39 GMT</pubDate>
    <dc:creator>RohiniMathur</dc:creator>
    <dc:date>2019-09-23T18:03:39Z</dc:date>
    <item>
      <title>Length Value of a column in pyspark</title>
      <link>https://community.databricks.com/t5/data-engineering/length-value-of-a-column-in-pyspark/m-p/27747#M19595</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;i am using pyspark 2.12&lt;/P&gt;
&lt;P&gt;After Creating Dataframe can we measure the length value for each row.&lt;/P&gt;
&lt;P&gt;For Example: I am measuring length of a value in column 2&lt;/P&gt;
&lt;P&gt;Input file &lt;/P&gt;
&lt;P&gt;|TYCO|1303| &lt;/P&gt;
&lt;P&gt;|EMC |120989| &lt;/P&gt;
&lt;P&gt;|VOLVO|102329|&lt;/P&gt;
&lt;P&gt; |BMW|130157|&lt;/P&gt;
&lt;P&gt; |FORD|004| &lt;/P&gt;
&lt;P&gt;Output in Dataframe i am trying to get like&lt;/P&gt;
&lt;P&gt;|TYCO|1303|4&lt;/P&gt;
&lt;P&gt;|EMC |120989|6&lt;/P&gt;
&lt;P&gt;|VOLVO|1023295|7&lt;/P&gt;
&lt;P&gt;|BMW|130157|6&lt;/P&gt;
&lt;P&gt;|FORD|004| 3&lt;/P&gt;
&lt;P&gt;Please suggest if it is possible.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 18:03:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/length-value-of-a-column-in-pyspark/m-p/27747#M19595</guid>
      <dc:creator>RohiniMathur</dc:creator>
      <dc:date>2019-09-23T18:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Length Value of a column in pyspark</title>
      <link>https://community.databricks.com/t5/data-engineering/length-value-of-a-column-in-pyspark/m-p/27748#M19596</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A target="_blank" href="https://"&gt;length&lt;/A&gt; function for this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql.functions import length
mock_data = [('TYCO', '1303'),('EMC', '120989'), ('VOLVO', '102329'),('BMW', '130157'),('FORD', '004')]
df = spark.createDataFrame(mock_data, ['col1', 'col2'])
df2 = df.withColumn('length_col2', length(df.col2))
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Published notebook to show full example:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/3249544772526824/170361741785841/7123846766950497/latest.html" target="test_blank"&gt;https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/3249544772526824/170361741785841/7123846766950497/latest.html&lt;/A&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 18:13:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/length-value-of-a-column-in-pyspark/m-p/27748#M19596</guid>
      <dc:creator>lee</dc:creator>
      <dc:date>2019-09-23T18:13:06Z</dc:date>
    </item>
  </channel>
</rss>

