While working with data in Pandas, we perform a vast array of operations on the data to get the data in the desired form. One of these operations could be that we want to create new columns in the DataFrame based on the result of some operations on the existing columns in the DataFrame. Let’s discuss several ways in which we can do that.
Given a Dataframe containing data about an event, we would like to create a new column called ‘Discounted_Price’, which is calculated after applying a discount of 10% on the Ticket price.
Solution #1: We can use
DataFrame.apply() function to achieve this task.
Now we will create a new column called ‘Discounted_Price’ after applying a 10% discount on the existing ‘Cost’ column.
Solution #2: We can achieve the same result by directly performing the required operation on the desired column element-wise.
- Adding new column to existing DataFrame in Pandas
- Split a text column into two columns in Pandas DataFrame
- Python | Creating a Pandas dataframe column based on a given condition
- Create a column using for loop in Pandas Dataframe
- Drop rows from the dataframe based on certain condition applied on a column
- How to rename columns in Pandas DataFrame
- Difference of two columns in Pandas dataframe
- Python | Pandas DataFrame.columns
- How to select multiple columns in a pandas dataframe
- Iterating over rows and columns in Pandas DataFrame
- How to drop one or multiple columns in Pandas Dataframe
- Dealing with Rows and Columns in Pandas DataFrame
- Getting frequency counts of a columns in Pandas DataFrame
- Conditional operation on Pandas DataFrame columns
- Join two text columns into a single column in Pandas
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.