In [34]:
using CSV
using Chain 
using DataFramesMeta
using Statistics
import DataFrames as df
In [0]:
 
In [0]:
 
In [8]:
ENV["COLUMNS"] = 350
Out[8]:
350
In [11]:
data = DataFrame(CSV.File("Open-Data-Bundestagswahl1343_wue_stadt.csv"))
Out[11]:

13 rows × 71 columns (omitted printing of 31 columns)

datumwahlagsgebiet-nrgebiet-namemax-schnellmeldungenanz-schnellmeldungenA1A2A3ABB1CDEFD1F1D2F2D3F3D4F4D5F5D6F6D7F7D8F8D9F9D10F10D11F11D12
StringStringInt64MissingStringInt64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64
126.09.2021Wahl zum Deutschen Bundestag9663000missingALTSTADT3232595991170150761252987611071242242124872814233318452030047715301538444942677938353802331677101150501630
226.09.2021Wahl zum Deutschen Bundestag9663000missingZELLERAU121243134097084106226390577614941618513701173122112400393589529184417315135412461599537069090760
326.09.2021Wahl zum Deutschen Bundestag9663000missingDÜRRBACHTAL10101936251704453369023844336471736731410117462774402424073806866741531301661104921059060230
426.09.2021Wahl zum Deutschen Bundestag9663000missingGROMBÜHL10102900318806088455830524245161445448837338448450202479495155314463643761701186538064020660
526.09.2021Wahl zum Deutschen Bundestag9663000missingLINDLEINSMÜHLE44191613860330221281303382090232105726646473494027524818426625513196128552311016010150
626.09.2021Wahl zum Deutschen Bundestag9663000missingFRAUENLAND2626608483740144581207479589111983411203333982905186721670520148214293630341758560039926517281013101001110
726.09.2021Wahl zum Deutschen Bundestag9663000missingSANDERAU161644636685011148919163616391282991622273195115741681033110089793020288852955426822413356084040780
826.09.2021Wahl zum Deutschen Bundestag9663000missingHEIDINGSFELD141436524135077875934391876585844589021341788109512680405587549113810742522572821819853070060460
926.09.2021Wahl zum Deutschen Bundestag9663000missingHEUCHELHOF12124108240806516429122951054186544237149912748588560645555425557565215161229843518048000180
1026.09.2021Wahl zum Deutschen Bundestag9663000missingSTEINBACHTAL88131823680368632272262153212232251089959405443012753554885681713013181623010032010160
1126.09.2021Wahl zum Deutschen Bundestag9663000missingVERSBACH882262307505337436829494843201743511492125186494302794894438398641831632141586524043030320
1226.09.2021Wahl zum Deutschen Bundestag9663000missingLENGFELD1414362045290814964184321696349256393225018891265137804417807141166116825224129817580410620120540
1326.09.2021Wahl zum Deutschen Bundestag9663000missingROTTENBAUER6614831694031772608160859254923258594476944249402322842964984988281120843919016040120
In [2]:
select(data,-:A2)
MethodError: no method matching -(::Symbol)
Closest candidates are:
  -(::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}) at /ext/julia/julia-1.7.1/share/julia/base/int.jl:85
  -(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at /ext/julia/julia-1.7.1/share/julia/base/int.jl:86
  -(::Union{UInt16, UInt32, UInt64, UInt8}, ::BigInt) at /ext/julia/julia-1.7.1/share/julia/base/gmp.jl:532
  ...

Stacktrace:
 [1] top-level scope
   @ In[2]:1
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
In [24]:
names(data)
data2 = select(data,names(data)[19:end])
Out[24]:

13 rows × 53 columns (omitted printing of 3 columns)

F1D2F2D3F3D4F4D5F5D6F6D7F7D8F8D9F9D10F10D11F11D12F12D13F13D14F14D15F15D16F16D17F17D18F18D19F19D20F20D21F21D22F22D23F23D24F24D25F25D26
Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64Int64
1233318452030047715301538444942677938353802331677101150501630450202801203072421230802012029741039070
21173122112400393589529184417315135412461599537069090760210108070303172790203080033170240150
311746277440242407380686674153130166110492105906023021010603000184430200010219607070
473384484502024794951553144636437617011865380640206602600030702019348060201002914012090
56464734940275248184266255131961285523110160101505010303010162190100030152010030
6290518672167052014821429363034175856003992651728101310100111040050160900042821540703070366340240120
719511574168103311008979302028885295542682241335608404078044010130702001911160700050166230180160
81788109512680405587549113810742522572821819853070060460100204060100172770704050232130180100
912748588560645555425557565215161229843518048000180180302010000116758010101011560170100
109594054430127535548856817130131816230100320101603010500000058350102030110500050
111251864943027948944383986418316321415865240430303202502030130102109570301050413709080
121889126513780441780714116611682522412981758041062012054027040808020216587060104002190270170
137694424940232284296498498828112084391901604012013000006000089340201020023803050
In [30]:
typeof(data2)
Out[30]:
DataFrame
In [36]:
df1 = DataFrame(a=["x", "y"], b=[1.0, 2.0], c=[3, 4], d=[true, false])
Out[36]:

2 rows × 4 columns

abcd
StringFloat64Int64Bool
1x1.031
2y2.040
In [37]:
df.permutedims(df1, 1) # note the column types
MethodError: no method matching permutedims(::DataFrame, ::Int64)
Closest candidates are:
  permutedims(::StridedArray, ::Any) at /ext/julia/julia-1.7.1/share/julia/base/multidimensional.jl:1498
  permutedims(::LinearAlgebra.Diagonal, ::Any) at /ext/julia/julia-1.7.1/share/julia/stdlib/v1.7/LinearAlgebra/src/diagonal.jl:565
  permutedims(::SparseArrays.AbstractSparseMatrixCSC, ::Any) at /ext/julia/julia-1.7.1/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:1094
  ...

Stacktrace:
 [1] top-level scope
   @ In[37]:1
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
In [20]:
@select(data, :A1,:A2)
LoadError: ArgumentError: Expressions not of the form `y = f(:x)` are currently disallowed.
in expression starting at In[20]:1

Stacktrace:
 [1] fun_to_vec(ex::Expr; nolhs::Bool, gensym_names::Bool, wrap_byrow::Bool)
   @ DataFramesMeta /ext/julia/depot/packages/DataFramesMeta/z0mc6/src/parsing.jl:215
 [2] (::DataFramesMeta.var"#30#31"{Bool})(ex::Expr)
   @ DataFramesMeta ./none:0
 [3] iterate(::Base.Generator{Vector{Any}, DataFramesMeta.var"#30#31"{Bool}})
   @ Base ./generator.jl:47
 [4] select_helper(x::Symbol, args::Expr)
   @ DataFramesMeta /ext/julia/depot/packages/DataFramesMeta/z0mc6/src/macros.jl:976
 [5] var"@select"(__source__::LineNumberNode, __module__::Module, x::Any, args::Vararg{Any})
   @ DataFramesMeta /ext/julia/depot/packages/DataFramesMeta/z0mc6/src/macros.jl:1078
 [6] eval
   @ ./boot.jl:373 [inlined]
 [7] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
In [31]:
 permutedims(data2, 1)
MethodError: no method matching permutedims(::DataFrame, ::Int64)
Closest candidates are:
  permutedims(::StridedArray, ::Any) at /ext/julia/julia-1.7.1/share/julia/base/multidimensional.jl:1498
  permutedims(::LinearAlgebra.Diagonal, ::Any) at /ext/julia/julia-1.7.1/share/julia/stdlib/v1.7/LinearAlgebra/src/diagonal.jl:565
  permutedims(::SparseArrays.AbstractSparseMatrixCSC, ::Any) at /ext/julia/julia-1.7.1/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:1094
  ...

Stacktrace:
 [1] top-level scope
   @ In[31]:1
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
In [29]:
 
Out[29]:
permutedims(A::AbstractArray, perm)

Permute the dimensions of array A. perm is a vector or a tuple of length ndims(A) specifying the permutation.

See also permutedims!, PermutedDimsArray, transpose, invperm.

Examples¶

jldoctest
julia> A = reshape(Vector(1:8), (2,2,2))
2×2×2 Array{Int64, 3}:
[:, :, 1] =
 1  3
 2  4

[:, :, 2] =
 5  7
 6  8

julia> permutedims(A, (3, 2, 1))
2×2×2 Array{Int64, 3}:
[:, :, 1] =
 1  3
 5  7

[:, :, 2] =
 2  4
 6  8

julia> B = randn(5, 7, 11, 13);

julia> perm = [4,1,3,2];

julia> size(permutedims(B, perm))
(13, 5, 11, 7)

julia> size(B)[perm] == ans
true

permutedims(m::AbstractMatrix)

Permute the dimensions of the matrix m, by flipping the elements across the diagonal of the matrix. Differs from LinearAlgebra's transpose in that the operation is not recursive.

Examples¶

```jldoctest; setup = :(using LinearAlgebra) julia> a = [1 2; 3 4];

julia> b = [5 6; 7 8];

julia> c = [9 10; 11 12];

julia> d = [13 14; 15 16];

julia> X = [[a] [b]; [c] [d]] 2×2 Matrix{Matrix{Int64}}: [1 2; 3 4] [5 6; 7 8] [9 10; 11 12] [13 14; 15 16]

julia> permutedims(X) 2×2 Matrix{Matrix{Int64}}: [1 2; 3 4] [9 10; 11 12] [5 6; 7 8] [13 14; 15 16]

julia> transpose(X) 2×2 transpose(::Matrix{Matrix{Int64}}) with eltype Transpose{Int64, Matrix{Int64}}: [1 3; 2 4] [9 11; 10 12] [5 7; 6 8] [13 15; 14 16]


---

permutedims(v::AbstractVector)


Reshape vector `v` into a `1 × length(v)` row matrix. Differs from `LinearAlgebra`'s [`transpose`](@ref) in that the operation is not recursive.

# Examples

```jldoctest; setup = :(using LinearAlgebra)
julia> permutedims([1, 2, 3, 4])
1×4 Matrix{Int64}:
 1  2  3  4

julia> V = [[[1 2; 3 4]]; [[5 6; 7 8]]]
2-element Vector{Matrix{Int64}}:
 [1 2; 3 4]
 [5 6; 7 8]

julia> permutedims(V)
1×2 Matrix{Matrix{Int64}}:
 [1 2; 3 4]  [5 6; 7 8]

julia> transpose(V)
1×2 transpose(::Vector{Matrix{Int64}}) with eltype Transpose{Int64, Matrix{Int64}}:
 [1 3; 2 4]  [5 7; 6 8]
In [10]:
DataFrame(CSV.File("okvote-fields.tsv"))
Out[10]:

70 rows × 3 columns

columnstimmepartei_beschreibung
StringString?String
1datummissingDatum des Wahltermins
2wahlmissingName der Wahl
3agsmissingAGS der Behörde
4gebiet-nrmissingNummer des Wahlgebiets
5gebiet-namemissingName des Wahlgebiets
6max-schnellmeldungenmissingAnzahl an insgesamt erwarteten Schnellmeldungen im Wahlgebiet
7anz-schnellmeldungenmissingAnzahl an bisher eingegangenen Schnellmeldungen im Wahlgebiet
8A1missingWahlberechtigte ohne Sperrvermerk 'W'
9A2missingWahlberechtigte mit Sperrvermerk 'W'
10A3missingWahlberechtigte nicht im Wählerverzeichnis
11AmissingWahlberechtigte insgesamt
12BmissingWähler
13B1missingWähler mit Wahlschein
14CErststimmenUngültige Erststimmen
15DErststimmenGültige Erststimmen
16EZweitstimmenUngültige Zweitstimmen
17FZweitstimmenGültige Zweitstimmen
18D1ErststimmenChristlich-Soziale Union in Bayern e.V.
19F1ZweitstimmenChristlich-Soziale Union in Bayern e.V.
20D2ErststimmenSozialdemokratische Partei Deutschlands
21F2ZweitstimmenSozialdemokratische Partei Deutschlands
22D3ErststimmenAlternative für Deutschland
23F3ZweitstimmenAlternative für Deutschland
24D4ErststimmenFreie Demokratische Partei
25F4ZweitstimmenFreie Demokratische Partei
26D5ErststimmenBÜNDNIS 90/DIE GRÜNEN
27F5ZweitstimmenBÜNDNIS 90/DIE GRÜNEN
28D6ErststimmenDIE LINKE
29F6ZweitstimmenDIE LINKE
30D7ErststimmenFREIE WÄHLER
⋮⋮⋮⋮
In [0]: