Python - How to Add Multiple Columns in DataFrame
Mukesh Singh
In this tutorial, you will learn "How to Add Multiple Columns in DataFrame" in Pandas. For this I used Python 3.12 runtime.
Pandas is a powerful and flexible open-source data analysis and data manipulation library for Python. It provides data structures and functions needed to manipulate structured data seamlessly.
Explanation: Create a Sample DataFrame: We start by creating a sample DataFrame.
Define a Function to Generate Multiple Columns: This function takes a row of the DataFrame as input and returns a pd.Series object with new columns as # SellingAmt = Quantity * SellingPrice # Profit = SalesAmount - ProductCost
Use apply to Apply the Function Row-wise: We use the apply method with axis=1 to apply the custom function to each row of the DataFrame.
⭐To learn more, please follow us - http://www.sql-datatools.com ⭐To Learn more, please visit our YouTube channel at - http://www.youtube.com/c/Sql-datatools ⭐To Learn more, please visit our Instagram account at - https://www.instagram.com/asp.mukesh/ ⭐To Learn more, please visit our twitter account at - https://twitter.com/macxima ⭐To Learn more, please visit our Medium account at - https://medium.com/@macxima ... https://www.youtube.com/watch?v=JJ06bhTTmnQ
20887021 Bytes