From the course: Complete Guide to Databricks for Data Engineering
Unlock this course with a free trial
Join today to access over 24,600 courses taught by industry experts.
Add or remove columns in PySpark - Databricks Tutorial
From the course: Complete Guide to Databricks for Data Engineering
Add or remove columns in PySpark
- [Instructor] Sometimes you come across a situation where you want to add some extra columns into your data frame, which is not available in the file which you have read. How you can do that? Let us see. Imagine that we have this our data frame. And in this data frame, I want to add one extra column. For that I can use the function call withColumn. withColumn function will add one extra column along with all other columns which already there in the data frame. So the new data frame we should get will have that one extra column. For example, let's just set a new column as, I call it, like Salary. And the value for the Salary column, I just keep it something, let's say column, and whatever is their age. Let's try to make the salary multiply by thousand. So their salary would be is multiple of their age. And let's create this column. If I do df1.printSchema, you can see that this new data frame one will have all the columns which was there in the data frame df, plus one extra column…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Use filter and where transformations in PySpark8m 30s
-
(Locked)
Add or remove columns in PySpark8m 56s
-
(Locked)
Use the select function in PySpark6m 16s
-
(Locked)
Use UNION and DISTINCT in PySpark5m 31s
-
(Locked)
Handle nulls in PySpark8m 39s
-
(Locked)
Use sortBy and orderBy in PySpark9m 38s
-
(Locked)
Use groupBy and aggregation in PySpark8m 27s
-
(Locked)
Manipulate strings in PySpark14m 21s
-
(Locked)
Handle date manipulation in PySpark9m 37s
-
(Locked)
Handle timestamp manipulation in PySpark4m 29s
-
-
-
-
-
-
-
-
-
-
-
-