From the course: Advanced Hands-On Python: Working with Excel and Spreadsheet Data

Unlock the full course today

Join today to access over 24,600 courses taught by industry experts.

Manipulating DataFrame content

Manipulating DataFrame content

- [Instructor] Data frames make it easy to perform all kinds of manipulation on the data that they contain. So for this example, I'm going to focus on several of the more common operations. Let's open up pandas_manipulate. And you can see in my example file, I already have some code that reads the Inventory.csv file into a data frame. So for the first example, let's create a new column of data. We did this earlier in the course manually, but now we're going to accomplish the same thing using pandas. We're going to add a column named margin that represents the difference between the consumer price and the wholesale price for each product. So all I need to do is name the new column and use a formula to calculate the difference between the other two columns. So watch how easy this is. I'm just simply going to on the data frame make a new column. I'm going to call that margin. And I'm going to set that equal to the difference between the consumer price. And I'm going to subtract off the…

Contents