Standaarddeviatie met Python
De eerste functie is van numpy
, en de tweede methode is van pandas
. Bekijk het voorbeeld van het berekenen van de standaarddeviatie voor de work_year
:
99
1
2
3
4
5
6
7
8
9
10
11
12
import pandas as pd
import numpy as np
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/update/ds_salaries_statistics', index_col = 0)
# Calculate the standard deviation using the function from the NumPy library
std_1 = np.std(df['salary_in_usd'])
# Calculate the standard deviation using the function from the pandas library
std_2 = df['salary_in_usd'].std()
print('The standard deviation using NumPy library is', round(std_1, 2))
print('The standard deviation using pandas library is', round(std_2, 2))
123456789101112import pandas as pd import numpy as np df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/update/ds_salaries_statistics', index_col = 0) # Calculate the standard deviation using the function from the NumPy library std_1 = np.std(df['salary_in_usd']) # Calculate the standard deviation using the function from the pandas library std_2 = df['salary_in_usd'].std() print('The standard deviation using NumPy library is', round(std_1, 2)) print('The standard deviation using pandas library is', round(std_2, 2))
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 5
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.