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:06 objects as they're shown. So remember we have our DFM foe and we've got company
0:11 We've got invoice. We've got the skew in the product which are coming through
0:15 his objects. So let's say we wanted to turn the company into an upper case
0:21 Once again, we get the attributes air because pandas doesn't know what we're trying
0:27 to do. There is no attributes for pandas Siri's to convert it to upper.
0:33 So we need to tell it that we're trying to do a string manipulation and now
0:38 it works so similar to what we did with dot d.
0:40 T. Now we use dot str and there's a bunch of string manipulations that you
0:46 will likely encounter as you start to wrangle and manipulate your data.
0:51 So this you can lower case your values into title case s o.
0:58 Many of the string functions that you would expect to use just in General Python are
1:03 available in pandas. Another one that you might want to use is length and similar
1:11 to what we did earlier. If you want to actually make sure this gets incorporate
1:16 any transformation To make it incorporate back into your data frame.
1:20 You need to make sure you re assign it,
1:22 so call it upper company. And now we have a new columns.
1:32 Has upper company that has the company name all uppercase.
1:37 Now we've already talked a little bit about how to do some basic math,
1:40 and I want to just tie this back to the different data types.
1:44 So what? What pandas knows is if you have a data type that in this
1:49 case is an end or afloat,
1:51 so it's numeric data type. Then you could do mathematical operations so you can think
1:56 about the mathematical formulas plus minus multiplication as access er's similar to what we did for
2:04 the strings and the daytime data types.
2:08 So, for instance, if we have the extended amount and we wanted to multiply
2:13 it by 0.9, so essentially give a 10% discount,
2:17 you just use the standard math functions and pandas knows because it is a numeric value
2:23 It understands what this operator is,
2:26 so you don't need to use an excess.
2:28 Er Pan is smart enough to do that for you.
2:31 There is another way to do math in pandas,
2:35 and I want to highlight it,
2:36 so you're aware of it. So instead of using the asterisk like you would just
2:43 to do a normal math multiplication in Python,
2:46 there are different operators on this one.
2:49 There is when a dot mole there's a division and add,
2:53 and for the most part, we're not going to talk about those in the in
2:58 this course, it's generally I would recommend using mathematical operations As you get started.
3:06 These types of functions will be useful form or advanced chaining of pandas operations,
3:12 so I want you aware of it.
3:13 But I'm not going to spend a lot of time in the course talking about how
3:17 to use them. So to close this out,
3:19 I want to dio a little more complex mathematical operation.
3:23 So let's say we want to create a new price and that new prices 5% higher
3:29 than the old price. And so then we've created a new price column that is
3:37 5% higher, and then we want to see what the new extended amount is,
3:41 so we have to multiply that times the new price and the new quant and the
3:46 old quantity. If we do that and see this new price is going to be
3:52 out here at the end 17.
3:53 85. So the old price was 17.
3:56 We've added that 5% to it,
3:59 and then this is the new extended amount.
4:01 And if you want to see what the actual total amount is,
4:05 weaken dio simple formula on that as well.
4:11 So this tells us that the original extended amount was 510,000,
4:16 and now we are at 535,000,