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 |
+--------------+-------+-------+-------------+