Skip to content

WIP: cambios de la clase de ayer #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions clases/01_introduccion/pandas_intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ def rate_height(height):

df['Skin color'].replace({"-": None}, inplace=True)

df[df["Skin color"] != "-"]

df['Skin color']

# ## Eliminar filas con nulos

df

df = df.dropna(subset=['Skin color'])
df = df.dropna(subset=['Skin color'], )
df

# # Unir información de distintas tablas
Expand All @@ -185,13 +187,22 @@ def rate_height(height):

# Tenemos duplicados!

df.merge(df, left_on='Skin color', right_on='Skin color')[['Race_x', 'Race_y']]
# +
df2 = df.copy()

df.merge(df2, left_on='Skin color', right_on='Skin color', )[['Race_x', 'Race_y']]
# -

df1 = pd.DataFrame({"a":[2,2,3], "b":[4,5,6]})
df2 = pd.DataFrame({"c":[2,3,4], "b":[11,12,13]})
df1.merge(df2, left_on="a", right_on="c", how="outer")
df1.merge(df2, left_index=True, right_index=True, how="outer")

# Tenemos que sacar los que son iguales en ambas columnas!

same_skin_color = df.merge(df, left_on='Skin color', right_on='Skin color')[
['Race_x', 'Race_y']
].drop_duplicates()
]#.drop_duplicates()
same_skin_color[same_skin_color.Race_x != same_skin_color.Race_y]

# +
Expand Down Expand Up @@ -235,6 +246,8 @@ def rate_height(height):
df_1 = pd.DataFrame({'col_1': range(1, 10), 'col_2': range(1, 10)})
df_2 = pd.DataFrame({'col_1': range(11, 20), 'col_2': range(11, 20)})

df_2

df_1.pipe(len)

df_2.pipe(len)
Expand All @@ -259,6 +272,8 @@ def rate_height(height):

df.groupby("Race")

callable(list)

df.groupby("Race").agg(list)

(df['Alignment'] == 'good').mean() * 100
Expand Down Expand Up @@ -299,6 +314,8 @@ def perc_good(grouping):
over5 = df.Race.value_counts(normalize=True) > 0.05
mutants_over5 = df.Race.value_counts()[over5]

mutants_over5

# Teniendo la indexacion, veamos como resolverlo con `isin`

df[df.Race.isin(mutants_over5.index)].head(5)
Expand All @@ -322,6 +339,7 @@ def perc_good(grouping):
},
)

# + [markdown] jp-MarkdownHeadingCollapsed=true tags=[]
# # Checkpoint
#
# Desde el siguiente snippet:
Expand All @@ -332,6 +350,7 @@ def perc_good(grouping):
# ```
#
# Encontrar el promedio de altura por raza, considerando solo los personajes _buenos_.
# -

# # Sobre vistas y columnas

Expand All @@ -346,6 +365,8 @@ def alignment_to_numeric(alignment):
df_marvel['numeric_alineation'] = df_marvel.Alignment.apply(alignment_to_numeric)
# -

df_marvel

df_marvel = df[df.Publisher == 'Marvel Comics'].copy()

df_marvel.loc[:, 'numeric_alineation'] = df_marvel.Alignment.apply(alignment_to_numeric)
Expand All @@ -366,6 +387,8 @@ def alignment_to_numeric(alignment):

df.name.apply(lambda x: x.lower())

df.name.str.lower()

# Entre [otras](https://pandas.pydata.org/pandas-docs/stable/user_guide/text.html)

# # Manejo de fechas
Expand Down