WEBVTT

00:01.050 --> 00:04.180
Welcome to the second part on arithmetic operations.

00:04.320 --> 00:10.920
And in this video we will add subtract multiply and divide a single scalar value to a column and also

00:10.920 --> 00:12.460
to a whole data frame.

00:12.690 --> 00:17.250
And by doing so we are creating new data and new features for our data analysis.

00:17.790 --> 00:25.410
So again here we are working with our Titanic dataset and we have still imported pandas as PTA and still

00:25.410 --> 00:26.730
we have few on the right hand side.

00:26.730 --> 00:33.000
Our new column number for ladies and we all know that the tragic disaster happened in the year nineteen

00:33.000 --> 00:38.730
hundred and twelve and actually for most of the passengers we know the eights and nineteen hundred and

00:38.730 --> 00:39.120
twelve.

00:39.120 --> 00:45.890
So here we have our H column and at the point in time when the disaster happened for example the passenger

00:46.080 --> 00:53.580
with the index labor to was 26 years old and by combining these two information so we know that the

00:53.580 --> 00:58.590
disaster was in nineteen hundred and twelve and we have for the ages in nineteen hundred and twelve

01:00.020 --> 01:03.660
and therefore we can calculate to the approximate year of birth.

01:03.660 --> 01:11.510
So plus minus one year and we can do this by subtracting the h in nineteen hundred and twelve from nineteen

01:11.510 --> 01:12.500
hundred and twelve.

01:12.500 --> 01:15.420
So let's do this year.

01:16.080 --> 01:21.540
So for example the very first passenger was twenty two years old in nineteen hundred and twelve and

01:21.540 --> 01:28.110
therefore his approximate year of birth was eighteen hundred and ninety plus minus one and next extra

01:28.100 --> 01:30.960
we can do the same with the sub method.

01:31.010 --> 01:36.920
So first of all we take the H column and then from the H column we subtract nineteen hundred and twelve

01:37.870 --> 01:43.720
and by doing the other way around us here we are getting negative fair use and we can turn these negative

01:43.720 --> 01:47.800
values to positive by multiplying all the values by minus one.

01:48.220 --> 01:53.380
So we are actually changing your mind method after the sub method and actually we shouldn't have any

01:53.380 --> 02:01.590
problems with and a values in the H column because here at the beginning of our section so he'll be

02:01.590 --> 02:04.820
replaced all and a radius by the mean.

02:04.870 --> 02:13.030
So this will see are actually not necessary and it's anyway the default setting and let's have a look

02:13.030 --> 02:14.410
here at our new data frame.

02:14.410 --> 02:16.200
So here we created the new column.

02:16.200 --> 02:20.370
Year of birth A.B. F. On the right side.

02:20.410 --> 02:22.940
The approximate year of birth.

02:23.170 --> 02:25.600
All right and also here we have our Fifth Column.

02:25.600 --> 02:31.420
And let's assume that the currency of the far column is the U.S. dollar and that we want to convert

02:31.450 --> 02:33.790
the U.S. dollar into a euro.

02:33.790 --> 02:39.490
And let's assume that the current fixed rate so the currency exchange rate is one point one.

02:39.850 --> 02:42.850
So for each euro we get one point one dollar.

02:43.720 --> 02:49.630
And in order to convert here our dollar farce we have to divide our fiat column by the exchange rate

02:49.630 --> 02:50.520
one point one.

02:51.340 --> 02:52.500
And we can do this.

02:52.510 --> 02:53.040
This the.

02:53.080 --> 02:54.360
This method.

02:54.400 --> 02:59.310
So we have the method for addition we have the sub method for subtraction.

02:59.350 --> 03:01.720
We have the my method for multiplication.

03:01.720 --> 03:07.750
And we have the diff method for division and therefore we are taking here the fact column and we divide

03:07.780 --> 03:15.230
the column by the scale of value f x rayed and here we have to define the scale of value as x rayed

03:15.250 --> 03:17.250
which is the one point one.

03:17.630 --> 03:20.260
And we are creating a new column Euro fair.

03:20.660 --> 03:24.520
And this is exactly the Fair column divided by the exchange rate.

03:24.530 --> 03:26.460
So let's do this.

03:26.750 --> 03:27.550
And that's again.

03:27.550 --> 03:29.540
Have a look here at our new data frame.

03:30.590 --> 03:34.020
So here we have added the euro Fair column.

03:34.130 --> 03:40.690
So you have the very first passenger paid to seven point two five dollar and by dividing the dollar

03:40.690 --> 03:43.140
fare by the dollar euro exchange rate.

03:43.150 --> 03:48.790
We are getting here a fair in euro terms on euro currency.

03:48.790 --> 03:54.280
All right so in the last session and in this session you created some new columns for our Titanic data

03:54.280 --> 03:54.790
frame.

03:55.060 --> 04:01.000
And now it's the time to drop some columns so that we can proceed our further analysis with a smaller

04:01.030 --> 04:07.810
and leaner data frame and actually want to drop the columns S.P. in part because here we created the

04:07.810 --> 04:10.040
new column number for latest.

04:10.330 --> 04:17.380
So we no longer need the columns the best P in parts and we can also delete the deck column because

04:17.380 --> 04:23.320
here we have over 600 missing values and also a year of birth and the euro Fair column.

04:23.320 --> 04:29.080
These are interesting and nice to know but for the time being we are also deleting these columns here

04:29.410 --> 04:30.370
and we can do this.

04:30.370 --> 04:36.400
This is the drop method and we have to set the in-place parameter to true as always.

04:36.520 --> 04:43.120
And then let's have a look here at our new data frame and here we only have two columns survived the

04:43.150 --> 04:48.100
peak last sex age fair embarked and the number of total relatives.

04:48.100 --> 04:52.390
All right now let's go back to our state's data frame and let's have a look here.

04:53.080 --> 04:58.470
So here we have the daily say it's for the say it's man Stephen Mike Andy and Paul.

04:59.440 --> 05:05.360
Now let's assume that the states men have daily fixed costs of five units.

05:05.410 --> 05:08.740
So in each day the states men have some states and revenue.

05:08.770 --> 05:13.080
But on the other hand side they have fixed costs of five units.

05:13.150 --> 05:20.940
So let's define you the variable fixed costs and all we want to calculate and determine the net savings.

05:20.950 --> 05:22.130
So the states.

05:22.180 --> 05:27.220
After subtracting the fixed costs and therefore we have to select here the columns.

05:27.220 --> 05:33.450
Monday to Friday so we all rows and all columns except the last two columns here.

05:33.460 --> 05:37.450
So by doing so we're creating a slice of our say instead of frame.

05:37.450 --> 05:39.620
Let's have a look here.

05:39.670 --> 05:42.960
So we have we have the slice of the say it's.

05:43.150 --> 05:48.040
And from each dailies say we now want to subtract the fixed costs of five.

05:48.310 --> 05:54.430
And we can do this with the sub method and we are passing the scale of value of fixed costs.

05:54.430 --> 05:58.030
And we have here for Stephen on Thursday and in value.

05:58.150 --> 05:59.310
We have to define that.

05:59.350 --> 06:03.940
We want to fill all in the end values with the value 0.

06:03.970 --> 06:05.320
So let's do this here

06:09.230 --> 06:16.000
and here we can see for example for Stephen on Thursday the net say after abstracting the fixed costs

06:16.000 --> 06:23.270
of 5 for sexually minus five because we treat it here the any end value as being zero.

06:23.300 --> 06:30.340
And before here we had the percentage bonus for say it's men and they actually had the different bonus.

06:30.340 --> 06:34.440
So Stephen had 12 percent Mike 15 and 10.

06:34.640 --> 06:38.350
And let's assume that all of these states men have the same percentage bonus.

06:38.360 --> 06:41.440
So 10 percent on the on the sales.

06:41.750 --> 06:48.250
And now again for each daily sale we can calculate the dollar bonus for the salesmen.

06:48.260 --> 06:51.590
So first of all we are slicing our sales data frame

06:54.390 --> 07:00.360
and then we are applying the model method and multiplying here each element by the percentage bonus

07:00.410 --> 07:01.270
0.01.

07:01.710 --> 07:05.520
And again here we want to treat all any end values as being zero

07:08.760 --> 07:12.090
and here we have further daily bonuses for the salesman.

07:12.090 --> 07:15.480
So for example Mike receives for his saves.

07:15.480 --> 07:18.670
On Wednesday seven point four bonus.

07:18.690 --> 07:19.070
All right.

07:19.080 --> 07:21.650
So now let's again check our daily sales.

07:21.960 --> 07:28.320
So we are slicing our sales data frame except the last two columns with the percentage bonus and the

07:28.320 --> 07:35.880
total weekly bonus here and that's assume that the bonus metric is not as simple as here.

07:35.880 --> 07:40.890
So by just multiplying a percentage bonus of 10 percent to I'd say it's data.

07:41.340 --> 07:44.770
But let's assume now that for each 10 say it is.

07:44.820 --> 07:47.310
So we have a lot size of 10.

07:47.310 --> 07:50.940
The salesman gets a bonus of one point two five.

07:51.240 --> 07:57.210
So for example if one salesman has on one day say it's off line you get nothing.

07:57.720 --> 08:01.440
And if the FSA is off 10 you get to one point two five.

08:01.530 --> 08:04.080
And if he has to they say it's off 15.

08:04.080 --> 08:05.660
You also get one point two five.

08:05.700 --> 08:13.260
And also with the 19 and then the case that a salesman has a daily sales of 20 then he get two times

08:13.260 --> 08:15.150
one point two five.

08:15.150 --> 08:19.000
So this is the the more complicated metric here.

08:19.020 --> 08:23.030
And for doing this we are having the very head for method flawed.

08:23.070 --> 08:30.410
So first of all here let's again slice here for our daily sales and then we are applying the flautist

08:30.510 --> 08:33.990
method and the flautist method actually divides.

08:33.990 --> 08:39.180
Here are the elements of for example 35 for by the lot size 10.

08:39.180 --> 08:41.740
So this is a three point four.

08:42.030 --> 08:46.090
And then it's around set down to the next integer so three.

08:46.110 --> 08:50.620
So we have here for the Monday sales of Stephen the 34.

08:50.640 --> 08:54.660
We have three completed lots with the lot size 10.

08:54.750 --> 08:57.780
And for example on Tuesday we have two completed lots.

08:57.810 --> 09:00.990
And on Wednesday one completed lot and so on.

09:00.990 --> 09:02.220
So we are using here.

09:02.220 --> 09:03.710
The flawed this method.

09:03.720 --> 09:04.770
So let's do this

09:09.460 --> 09:12.840
and first of all of course you have to define what size equals 10.

09:12.840 --> 09:15.580
And bonus pay a lot this one point two five.

09:17.050 --> 09:21.140
And here we can see the amount of completed lots for each daily say it.

09:21.160 --> 09:27.250
So here we have a three for Stephen on Monday two for Tuesday and one for Wednesday.

09:28.090 --> 09:34.130
And as we passed a zero to the pyramid the full value we have on Thursday also zero.

09:34.130 --> 09:40.840
And now we can multiply the daily lots by the bonus pair lot by changing the model method

09:45.490 --> 09:52.690
so he Steven had on Monday three completed lots and he gets a bonus of one point two five for each lot

09:53.020 --> 09:57.350
and therefore his bonus for Monday is three point seventy five.

09:57.490 --> 10:02.680
And we have done this here for all elements in our data frame and now we can also calculate that the

10:02.680 --> 10:05.150
total weekly bonus for let's salesman.

10:05.290 --> 10:13.220
And we can do this by changing or adding the sum method and we want to take this sum for all rows.

10:13.330 --> 10:15.700
So here for Stephen for Mike for India

10:19.350 --> 10:23.450
and again here we are getting the total weekly bonus for all faucets man.

10:23.490 --> 10:30.000
So these are some examples of Eric Medtech operations but pan now serious and also data frames with

10:30.000 --> 10:33.900
a single scalar value and actually no limitations.

10:33.900 --> 10:37.720
So you can make this as complicated as you like.

10:37.830 --> 10:44.370
And the good thing in Python here is that we can apply here multiple operations so flawed of multiplication

10:44.370 --> 10:47.670
and some actually only here within one line of code.

10:47.700 --> 10:49.510
So this is quite comfortable.

10:49.530 --> 10:55.380
And with this we are finished now with this session and I hope to see you also on the next video by.
