Skip to content
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a200be1
add literate jl files
miguelraz Apr 18, 2021
53433ec
traslation to spanish README
miguelraz Apr 18, 2021
88f18ed
translation to spanish 02
miguelraz Apr 18, 2021
cf1fcf7
translation to spanish 02_basicinfo.jl
miguelraz Apr 18, 2021
9b82f62
translation to spanish 03_missingvalues.jl
miguelraz Apr 18, 2021
51662a6
translation to spanish 04_loadsave.jl
miguelraz Apr 18, 2021
80375c0
translation to spanish 05_columns.jl
miguelraz Apr 18, 2021
9769314
spanish translation of 06_rows.jl
miguelraz Apr 18, 2021
3bb8157
spanish translation of 07_factors.jl
miguelraz Apr 18, 2021
b4a9c49
spanish translation of 08_joins.jl
miguelraz Apr 18, 2021
f461dd0
spanish translation of 09_reshaping.jl
miguelraz Apr 18, 2021
73a8f67
spanish translation of 10_transforms.jl
miguelraz Apr 18, 2021
49ea34a
update topics in README.md
miguelraz Apr 18, 2021
670e441
spanish translation of 11_performance.jl
miguelraz Apr 18, 2021
2f0ff63
spanish translation of 12_pitfalls.jl
miguelraz Apr 18, 2021
669663c
spanish translation of 13_extras.jl
miguelraz Apr 18, 2021
fb6a33c
Update literate_notebooks/src-ES/01_constructors.jl
miguelraz Apr 18, 2021
e2a8f25
Update literate_notebooks/src-ES/01_constructors.jl
miguelraz Apr 18, 2021
c862b3b
Update literate_notebooks/src-ES/01_constructors.jl
miguelraz Apr 18, 2021
8a31c93
Update literate_notebooks/src-ES/01_constructors.jl
miguelraz Apr 18, 2021
b88e172
spanish translation - add cheatsheets and language comparisons docs
miguelraz Apr 18, 2021
ed6c52c
Merge branch 'spanish-tutorials' of https://github.com/miguelraz/Juli…
miguelraz Apr 18, 2021
c0dd3c4
spanish translation - missed intro in 03_missingvalues.jl
miguelraz Apr 18, 2021
96a326b
spanish translation - add .toml files, fixup typos and word choices
miguelraz Apr 18, 2021
9edb30d
update stale 01_constructors.jl
miguelraz Apr 20, 2021
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
36 changes: 19 additions & 17 deletions literate_notebooks/src-ES/09_reshaping.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
# # Introduction to DataFrames
# # Introducción a DataFrames
# **[Bogumił Kamiński](http://bogumilkaminski.pl/about/), Apr 21, 2018**
# (Traducido por Miguel Raz Guzmán Macedo, 18 de Abril de 2021)

using DataFrames # load package
using DataFrames

# ## Reshaping DataFrames
# ## Reorganización de DataFrames

#-

# ### Wide to long
# ### De ancho a largo

x = DataFrame(id=[1,2,3,4], id2=[1,1,2,2], M1=[11,12,13,14], M2=[111,112,113,114])

#-

melt(x, :id, [:M1, :M2]) # first pass id-variables and then measure variables; meltdf makes a view
melt(x, :id, [:M1, :M2]) # primero pasamos las variables de identificación y luego las medioms; `meltdf` (melt = derretir) crea un `view`

#-

## optionally you can rename columns; melt and stack are identical but order of arguments is reversed
## opcionalmente puedes renombrar las columnas; `melt` y `stack` son idénticos, pero el orden de los argumentos se invierte
stack(x, [:M1, :M2], :id, variable_name=:key, value_name=:observed) # first measures and then id-s; stackdf creates view

#-

## if second argument is omitted in melt or stack , all other columns are assumed to be the second argument
## but measure variables are selected only if they are <: AbstractFloat
## si el segundo argumento se omite en `melt` o `stack`, todas las otras colummnas se asumen como en el segundo argumento
## pero las variables de medida se seleccionan sólo si <: AbstractFloat (es un subtipo de AbstractFloat)
#
melt(x, [:id, :id2])

#-

melt(x, [1, 2]) # you can use index instead of symbol
melt(x, [1, 2]) # puedes usar un índice en vez de un símbolo

#-

bigx = DataFrame(rand(10^6, 10)) # a test comparing creation of new DataFrame and a view
bigx = DataFrame(rand(10^6, 10)) # un test comparando la creación de un nuevo DataFrame y un `view`
bigx[:id] = 1:10^6
@time melt(bigx, :id)
@time melt(bigx, :id)
Expand All @@ -49,15 +51,15 @@ melt(x)

#-

melt(DataFrame(rand(3,2))) # by default stack and melt treats floats as value columns
melt(DataFrame(rand(3,2))) # por default, `stack` y `melt` tratan flotantes como columnas de valores

#-

df = DataFrame(rand(3,2))
df[:key] = [1,1,1]
mdf = melt(df) # duplicates in key are silently accepted
mdf = melt(df) # las llaves duplicadas se aceptan silenciosamente

# ### Long to wide
# ### Largo a ancho

x = DataFrame(id = [1,1,1], id2=['a','b','c'], a1 = rand(3), a2 = rand(3))

Expand All @@ -69,15 +71,15 @@ display(y)

#-

unstack(y, :id2, :variable, :value) # stndard unstack with a unique key
unstack(y, :id2, :variable, :value) # `unstack` estándar con llave única

#-

unstack(y, :variable, :value) # all other columns are treated as keys
unstack(y, :variable, :value) # todas las otras columnas se tratan como llaves

#-

## by default :id, :variable and :value names are assumed; in this case it produces duplicate keys
## por default `:id`, `:variable` y `:value` se asumen como nombres; en este caso eso produce llaves duplicadas
unstack(y)

#-
Expand All @@ -86,5 +88,5 @@ df = stack(DataFrame(rand(3,2)))

#-

unstack(df, :variable, :value) # unable to unstack when no key column is present
unstack(df, :variable, :value) # imposible hacer `unstack` cuando no hay columna-llave presente