Skip to content
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

Add section headings and row-by-row construction example #1416

Merged
merged 10 commits into from
Jul 11, 2018
Merged
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
52 changes: 49 additions & 3 deletions docs/src/man/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ julia> DataFrame(A = 1:4, B = ["M", "F", "F", "M"])

```

It is also possible to construct a `DataFrame` in stages:
### Constructing Column by Column

It is also possible to construct a `DataFrame` one column at a time.

```jldoctest dataframe
julia> df = DataFrame()
Expand Down Expand Up @@ -63,8 +65,8 @@ julia> df

```

The `DataFrame` we build in this way has 8 rows and 2 columns. You can check this using the
`size` function:
The `DataFrame` we build in this way has 8 rows and 2 columns.
You can check this using the `size` function:

```jldoctest dataframe
julia> size(df, 1) == 8
Expand All @@ -78,6 +80,46 @@ true

```

### Constructing Row by Row

It is also possible to construct a `DataFrame` row by row.

First a `DataFrame` with empty columns is constructed:

```jldoctest dataframe
julia> df = DataFrame(A = Int[], B = String[])
0×2 DataFrames.DataFrame
```

Rows can then be added as `Vector`s, where the row order matches the columns order:

```jldoctest dataframe
julia> push!(df, [1, "M"])
1×2 DataFrames.DataFrame
│ Row │ A │ B │
├─────┼───┼───┤
│ 1 │ 1 │ M │
```

Rows can also be added as `Dict`s, where the dictionary keys match the column names:

```jldoctest dataframe
julia> push!(df, Dict(:B => "F", :A => 2))
2×2 DataFrames.DataFrame
│ Row │ A │ B │
├─────┼───┼───┤
│ 1 │ 1 │ M │
│ 2 │ 2 │ F │
```

Note that constructing a `DataFrame` row by row is significantly less performant than
constructing it all at once, or column by column. For many use-cases this will not matter,
but for very large `DataFrame`s this may be a consideration.

## Working with Data Frames

### Taking a Subset

We can also look at small subsets of the data in a couple of different ways:

```jldoctest dataframe
Expand Down Expand Up @@ -113,6 +155,8 @@ julia> df[1:3, :]

```

### Summarizing with `describe`

Having seen what some of the rows look like, we can try to summarize the entire data set using `describe`:

```jldoctest dataframe
Expand All @@ -137,6 +181,8 @@ true

```

### Column-Wise Operations

We can also apply a function to each column of a `DataFrame` with the `colwise` function. For example:

```jldoctest dataframe
Expand Down