Hinzufügen einer neuen Spalte in der ersten ordinalen Position in einem PYSPARK -DatenframePython

Python-Programme
Anonymous
 Hinzufügen einer neuen Spalte in der ersten ordinalen Position in einem PYSPARK -Datenframe

Post by Anonymous »

Ich habe einen pyspark -Datenrahmen wie: < /p>

Code: Select all

+--------+-------+-------+
| col1   | col2  | col3  |
+--------+-------+-------+
|  25    |  01   |     2 |
|  23    |  12   |     5 |
|  11    |  22   |     8 |
+--------+-------+-------+
< /code>

und [url=viewtopic.php?t=14917]ich möchte[/url] einen neuen Datenfrequellen erstellen, indem ich eine neue Spalte wie folgt hinzufüge: < /p>

+--------------+-------+-------+-------+
| new_column   | col1  | col2  | col3  |
+--------------+-------+-------+-------+
|  0           |  01   |     2 |  0    |
|  0           |  12   |     5 |  0    |
|  0           |  22   |     8 |  0    |
+--------------+-------+-------+-------+
< /code>

Ich weiß, dass ich die Spalte hinzufügen kann durch: < /p>

df.withColumn("new_column", lit(0))
< /code>

, aber es fügt endlich so die Spalte hinzu: < /p>

+--------------+-------+-------+-------------+
| col1         | col1  | col2  | new_column  |
+--------------+-------+-------+-------------+
|  25          |  01   |     2 |  0          |
|  23          |  12   |     5 |  0          |
|  11          |  22   |     8 |  0          |
+--------------+-------+-------+-------------+

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post