Reputation: 211
I am trying to add blank rows on top of the pandas Dataframe data. Basically, some blank rows and some calculation for each row which contains calculations for Average etc. for that column. Can someone please help me how I can do this?
From:
A B D E F G H I J
0 -8 10 532 533 533 532 534 532 532
1 -8 12 520 521 523 523 521 521 521
2 -8 14 520 523 522 523 522 521 522
3 -4 2 526 527 527 528 528 527 529
4 -4 4 516 518 517 519 518 516 518
5 -4 6 528 529 530 531 530 528 530
6 -4 8 518 521 521 521 522 519 521
7 -4 10 524 525 525 525 525 524 524
8 -4 12 522 523 524 525 525 522 523
9 -2 2 525 526 527 527 527 525 527
10 -2 4 518 519 519 521 520 519 520
11 -2 6 520 522 522 522 522 520 523
12 -2 8 551 551 552 552 552 550 552
13 -2 10 533 534 535 536 535 534 535
14 -2 12 537 539 539 539 538 537 539
15 -2 14 528 530 530 531 530 529 530
16 -1 2 518 519 519 521 520 518 520
To:
A B D E F G H I J
Average 525.6 527.1 527.4 528.0 527.6 526.0 527.4
Sigma 8.6 8.3 8.5 8.1 8.3 8.3 8.4
Minimum 516 518 517 519 518 516 518
Maximum 551 551 552 552 552 550 552
0 -8 10 532 533 533 532 534 532 532
1 -8 12 520 521 523 523 521 521 521
2 -8 14 520 523 522 523 522 521 522
3 -4 2 526 527 527 528 528 527 529
4 -4 4 516 518 517 519 518 516 518
5 -4 6 528 529 530 531 530 528 530
6 -4 8 518 521 521 521 522 519 521
7 -4 10 524 525 525 525 525 524 524
8 -4 12 522 523 524 525 525 522 523
9 -2 2 525 526 527 527 527 525 527
10 -2 4 518 519 519 521 520 519 520
11 -2 6 520 522 522 522 522 520 523
12 -2 8 551 551 552 552 552 550 552
13 -2 10 533 534 535 536 535 534 535
14 -2 12 537 539 539 539 538 537 539
15 -2 14 528 530 530 531 530 529 530
16 -1 2 518 519 519 521 520 518 520
Upvotes: 0
Views: 2650
Reputation: 52266
I'd be sure that this is actually what you want to do, storing both data and summary statistics in the same frame is a little odd. That said, you can use concat
to stack dataframes.
In [23]: pd.concat([df.describe(), df])
Out[23]:
A B D E F G ...
count 17.000000 17.0000 17.000000 17.000000 17.000000 17.000000
mean -3.705882 8.0000 525.647059 527.058824 527.352941 528.000000
std 2.284861 4.1833 8.866659 8.518147 8.760288 8.396428
min -8.000000 2.0000 516.000000 518.000000 517.000000 519.000000
25% -4.000000 4.0000 520.000000 521.000000 522.000000 522.000000
50% -4.000000 8.0000 524.000000 525.000000 525.000000 525.000000
75% -2.000000 12.0000 528.000000 530.000000 530.000000 531.000000
max -1.000000 14.0000 551.000000 551.000000 552.000000 552.000000
0 -8.000000 10.0000 532.000000 533.000000 533.000000 532.000000
1 -8.000000 12.0000 520.000000 521.000000 523.000000 523.000000
2 -8.000000 14.0000 520.000000 523.000000 522.000000 523.000000
...
Upvotes: 1