import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('cars.csv')
# Desviación estandar
df['price_usd'].std()
# Rango = valor max - valor min
rango = df['price_usd'].max() - df['price_usd'].min()
rango
# Quartiles
median = df['price_usd'].median()
print(f'Media: {median}')
Q1 = df['price_usd'].quantile(q=0.25)
print(f'Q1: {Q1}')
Q3 = df['price_usd'].quantile(q=0.75)
print(f'Q3: {Q3}')
# Los cuartiles y percentiles son casos especificos de uso del Quantil
min_val = df['price_usd'].quantile(q=0)
print(f'Valor minimo: {min_val}')
max_val = df['price_usd'].quantile(q=1.0)
print(f'Valor maximo: {max_val}')
Media: 4800.0
Q1: 2100.0
Q3: 8990.0
Valor minimo: 1.0
Valor maximo: 50000.0
iqr = Q3 - Q1
print(f"Rango Intercuartil: {iqr}")
Rango Intercuartil: 6890.0
minlimit = Q1 - 1.5*iqr
maxlimit = Q3 + 1.5*iqr
print('rango para detección de outliers: {}, {}'.format(minlimit, maxlimit))
rango para detección de outliers: -8235.0, 19325.0
sns.set(rc={'figure.figsize':(11.7,8.27)})
# f, (ax_hist, ax_box) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.6, .4)})
sns.histplot(df['price_usd'])
sns.boxplot(df['price_usd'])
/shared-libs/python3.7/py/lib/python3.7/site-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
FutureWarning
sns.boxplot(x = 'engine_fuel', y= 'price_usd', data=df)
sns.set(rc={'figure.figsize':(11.7,8.27)})
f, (ax_hist, ax_box) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.6, .4)})
sns.histplot(df['price_usd'], ax=ax_hist)
sns.boxplot(df['price_usd'], ax=ax_box)
ax_hist.set(xlabel='')
/shared-libs/python3.7/py/lib/python3.7/site-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
FutureWarning
sns.boxplot(x = 'engine_fuel', y = 'price_usd', data = df)