|
| 1 | +--- |
| 2 | +title: "Diamantes" |
| 3 | +author: "Curso de Estadística Descriptiva" |
| 4 | +date: "8/1/2019" |
| 5 | +output: html_document |
| 6 | +--- |
| 7 | + |
| 8 | +```{r setup, include=FALSE} |
| 9 | +knitr::opts_chunk$set(echo = TRUE) |
| 10 | +``` |
| 11 | + |
| 12 | +# Análisis de los diamantes |
| 13 | + |
| 14 | +```{python} |
| 15 | +import numpy as np |
| 16 | +import pandas as pd |
| 17 | +import matplotlib |
| 18 | +from ggplot import diamonds |
| 19 | +
|
| 20 | +matplotlib.style.use("ggplot") |
| 21 | +
|
| 22 | +print(diamonds.shape) |
| 23 | +print(diamonds.head(10)) |
| 24 | +``` |
| 25 | + |
| 26 | +## Histograma |
| 27 | +```{python} |
| 28 | +diamonds.hist(column="carat", figsize=(8,8), color="blue", |
| 29 | + bins = 50, range = (0,3.5)) |
| 30 | +matplotlib.pyplot.show() |
| 31 | +``` |
| 32 | + |
| 33 | +## Filtro de outliers |
| 34 | +```{python} |
| 35 | +print(diamonds[diamonds["carat"]>3.5]) |
| 36 | +``` |
| 37 | + |
| 38 | +## Boxplots |
| 39 | +```{python} |
| 40 | +matplotlib.pyplot.clf() |
| 41 | +diamonds.boxplot(column = "price", figsize = (8,8)) |
| 42 | +matplotlib.pyplot.show() |
| 43 | +``` |
| 44 | + |
| 45 | +```{python} |
| 46 | +diamonds.boxplot(column = "price", by = "clarity", figsize = (8,8)) |
| 47 | +matplotlib.pyplot.show() |
| 48 | +``` |
| 49 | + |
| 50 | +```{python} |
| 51 | +diamonds.boxplot(column = "carat", by = "clarity", figsize = (8,8)) |
| 52 | +matplotlib.pyplot.show() |
| 53 | +``` |
| 54 | + |
| 55 | +## Densidades |
| 56 | +```{python} |
| 57 | +matplotlib.pyplot.clf() |
| 58 | +diamonds["carat"].plot(kind="density", figsize=(8,8), xlim=(0,5)) |
| 59 | +matplotlib.pyplot.show() |
| 60 | +``` |
| 61 | + |
| 62 | +## Tabla de frecuencias y Barplot |
| 63 | +```{python} |
| 64 | +carat_table = pd.crosstab(index=diamonds["clarity"], columns="count") |
| 65 | +print(carat_table) |
| 66 | +matplotlib.pyplot.clf() |
| 67 | +carat_table.plot(kind="bar", figsize=(8,8)) |
| 68 | +matplotlib.pyplot.show() |
| 69 | +``` |
| 70 | + |
| 71 | +```{python} |
| 72 | +carat_table_2 = pd.crosstab(index=diamonds["clarity"], columns=diamonds["color"]) |
| 73 | +print(carat_table_2) |
| 74 | +matplotlib.pyplot.clf() |
| 75 | +carat_table_2.plot(kind="bar", figsize=(8,8), stacked=True) |
| 76 | +matplotlib.pyplot.show() |
| 77 | +matplotlib.pyplot.clf() |
| 78 | +carat_table_2.plot(kind="bar", figsize=(8,8), stacked=False) |
| 79 | +matplotlib.pyplot.show() |
| 80 | +``` |
| 81 | + |
| 82 | +## Scatterplot |
| 83 | +```{python} |
| 84 | +matplotlib.pyplot.clf() |
| 85 | +diamonds.plot(kind="scatter", x = "carat", y = "price", figsize=(10,10), ylim=(0,20000), xlim = (0,6), alpha = 0.1) |
| 86 | +matplotlib.pyplot.show() |
| 87 | +``` |
| 88 | + |
0 commit comments