title: Separate a string column depending on first character appearance
body: <p>I want to separate the column of a Spark DataFrame into 2 different columns depending on the first appearance of a character, which in this case is an underscore ("_").</p>
  
  <p>I have prepared a 100% reproducible example:</p>
  
  <p>The mock Spark DataFrame is:</p>
  
  <pre><code>df = spark.createDataFrame(
      [
       (1, 1.8, 'newyork_3434_north'), 
       (4, 2.6, 'la_432432432_south'), 
       (6, 3.3, 'boston_234324_east'), 
       (8, 4.1, 'detroit_6757_west'), 
       (2, 5.7, 'miami_133123_north'), 
       (3, 6.2, 'atlanta_093394_west'), 
       (1, 6.1, 'houston_87342_east')
      ],
      ('ranking', "coordenate", "city")
  )
  </code></pre>
  
  <p>The above code creates a table like the following one:</p>
  
  <pre><code>ranking  coordenate  city
  1        1.8         newyork_3434_north
  4        2.6         la_432432432_south
  6        3.3         boston_234324_east
  8        4.1         detroit_6757_west
  2        5.7         miami_133123_north
  3        6.2         atlanta_093394_west 
  1        6.1         houston_87342_east
  </code></pre>
  
  <p>What I would like to do is separating the column city in 2 different columns depending on the location of the first underscore from left to right.</p>
  
  <p>The final desired table would be then something like:</p>
  
  <pre><code>ranking  coordenate  city       code
  1        1.8         newyork    3434_north
  4        2.6         la         432432432_south
  6        3.3         boston     234324_east
  8        4.1         detroit    6757_west
  2        5.7         miami      133123_north
  3        6.2         atlanta    093394_west
  1        6.1         houston    87342_east
  </code></pre>
  
  <p>I have seen several threads about this topic, but they do not speak about the first appearance of a character (<a href="https://stackoverflow.com/questions/39235704/split-spark-dataframe-string-column-into-multiple-columns">link_1</a>, <a href="https://stackoverflow.com/questions/41283478/split-contents-of-string-column-in-pyspark-dataframe">link_2</a>, etc.), but splitting by all specific characters that are on a string; or splitting by specific position of the character in the string.  </p>
  
  <p>I have also tried Python Pandas approach but as expected, it is not applicable in PySpark by extension or analogy (<a href="https://stackoverflow.com/questions/6903557/splitting-on-first-occurrence">link_3</a>) </p>
  
  <p>Thank you in advance for your help.</p>