#
Move from Excel to Python with Pandas Transcripts

Chapter: Data wrangling with Pandas

Lecture: String and math manipulations

Login or
purchase this course
to watch this video and the rest of the course contents.

0:00
now that we've done some data manipulation with daytime's let's take a look at strings or

0:07
objects as they're shown. So remember we have our DFM foe and we've got company

0:12
We've got invoice. We've got the skew in the product which are coming through

0:16
his objects. So let's say we wanted to turn the company into an upper case

0:22
Once again, we get the attributes air because pandas doesn't know what we're trying

0:28
to do. There is no attributes for pandas Siri's to convert it to upper. So we need to tell it that we're trying to do a string manipulation and now

0:39
it works so similar to what we did with dot d. T. Now we use dot str and there's a bunch of string manipulations that you

0:47
will likely encounter as you start to wrangle and manipulate your data. So this you can lower case your values into title case s o.

0:59
Many of the string functions that you would expect to use just in General Python are

1:04
available in pandas. Another one that you might want to use is length and similar

1:12
to what we did earlier. If you want to actually make sure this gets incorporate any transformation To make it incorporate back into your data frame.

1:21
You need to make sure you re assign it, so call it upper company. And now we have a new columns.

1:33
Has upper company that has the company name all uppercase. Now we've already talked a little bit about how to do some basic math,

1:41
and I want to just tie this back to the different data types. So what? What pandas knows is if you have a data type that in this

1:50
case is an end or afloat, so it's numeric data type. Then you could do mathematical operations so you can think

1:57
about the mathematical formulas plus minus multiplication as access er's similar to what we did for the strings and the daytime data types.

2:09
So, for instance, if we have the extended amount and we wanted to multiply it by 0.9, so essentially give a 10% discount,

2:18
you just use the standard math functions and pandas knows because it is a numeric value It understands what this operator is,

2:27
so you don't need to use an excess. Er Pan is smart enough to do that for you. There is another way to do math in pandas, and I want to highlight it,

2:37
so you're aware of it. So instead of using the asterisk like you would just to do a normal math multiplication in Python,

2:47
there are different operators on this one. There is when a dot mole there's a division and add,

2:54
and for the most part, we're not going to talk about those in the in

2:59
this course, it's generally I would recommend using mathematical operations As you get started.

3:07
These types of functions will be useful form or advanced chaining of pandas operations, so I want you aware of it.

3:14
But I'm not going to spend a lot of time in the course talking about how to use them. So to close this out,

3:20
I want to dio a little more complex mathematical operation. So let's say we want to create a new price and that new prices 5% higher

3:30
than the old price. And so then we've created a new price column that is 5% higher, and then we want to see what the new extended amount is,

3:42
so we have to multiply that times the new price and the new quant and the old quantity. If we do that and see this new price is going to be

3:53
out here at the end 17. 85. So the old price was 17. We've added that 5% to it, and then this is the new extended amount.

4:02
And if you want to see what the actual total amount is, weaken dio simple formula on that as well.

4:12
So this tells us that the original extended amount was 510,000, and now we are at 535,000,