2

I am using julia 1.4, I have a df like below. I want to add a new row to an existing dataframe at specific index. I found this but it seems old. I am using DataFrame(insert!.(eachcol(df), index, value)) to insert a row. I feel it's over performing. Because, it uses eachcol iterator and on top of result it converts array into Dataframe.

Sample Input:

│ Row │ x1       │ x2        │ x3       │ x4        │
│     │ Float64  │ Float64   │ Float64  │ Float64   │
├─────┼──────────┼───────────┼──────────┼───────────┤
│ 1   │ 0.236197 │ 0.509669  │ 0.353128 │ 0.615519  │
│ 2   │ 0.976431 │ 0.771457  │ 0.282455 │ 0.979453  │
│ 3   │ 0.445266 │ 0.0327924 │ 0.450912 │ 0.0135655 │

Expected Output:

4×4 DataFrame
│ Row │ x1       │ x2        │ x3       │ x4        │
│     │ Float64  │ Float64   │ Float64  │ Float64   │
├─────┼──────────┼───────────┼──────────┼───────────┤
│ 1   │ 0.236197 │ 0.509669  │ 0.353128 │ 0.615519  │
│ 2   │ 10.0     │ 12.0      │ 14.0     │ 16.0      │
│ 3   │ 0.976431 │ 0.771457  │ 0.282455 │ 0.979453  │
│ 4   │ 0.445266 │ 0.0327924 │ 0.450912 │ 0.0135655 │
Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111

0 Answers0