Computer scienceData scienceInstrumentsPandasData preprocessing with pandas

Modifying a DataFrame

Mean penguin bill

Report a typo

You are still working with the penguins_example DataFrame.

Let's now calculate the mean of the two columns, 'bill_length_mm' and 'bill_depth_mm' and create a new column called 'mean_bill' that will store the resulting values.

To compute the mean, you need to add bill length and bill depth and then divide the sum by two.

Note that the DataFrame is already stored in the variable penguins_example, so you just need to insert your code before the print() function. You don't need to import pandas here.

Sample Input 1:

     species	    bill_length_mm bill_depth_mm
0	Adelie	        41.1	    18.2
1	Adelie	        39.6	    17.7
2	Chinstrap	50.0	    19.5
3	Chinstrap	54.2	    20.8
4	Gentoo	        41.7	    14.7
5	Gentoo	        45.5	    13.9
6	Adelie          45.7	    15.5

Sample Output 1:

     species  bill_length_mm  bill_depth_mm  mean_bill
1     Adelie            41.1           18.2      29.65
2     Adelie            39.6           17.7      28.65
3  Chinstrap            50.0           19.5      34.75
4  Chinstrap            54.2           20.8      37.50
5     Gentoo            41.7           14.7      28.20
6     Gentoo            45.5           13.9      29.70
7     Adelie            45.7           15.5      30.60
Write a program in Python 3
# your code here. The dataset is already loaded, the variable that contains the DataFrame is called penguins_example

print(penguins_example)
___

Create a free account to access the full topic