Newer
Older
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "title-slide",
"slideshow": {
"id": "title-slide",
"slide_type": "slide"
}
},
"source": [
"# *Introduction to* Data Analysis and Plotting with Pandas\n",
"## JSC Tutorial\n",
"\n",
"Andreas Herten, Forschungszentrum Jülich, 26 February 2019"
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## My Motivation\n",
"\n",
"* I like Python\n",
"* I like plotting data\n",
"* I like sharing\n",
"* I think Pandas is awesome and you should use it too"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Tutorial Setup\n",
"\n",
"* 60 minutes (we might do this again for some advanced stuff if you want to)\n",
"* Alternating between lecture and hands-on\n",
"* Direct feedback via https://www.polleverywhere.com/"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Please open Jupyter Notebook of this session\n",
" - … either on your **local machine** (which has Pandas) \n",
" Download here\n",
" - … or on the **JSC Jupyter service** at https://jupyter-jsc.fz-juelich.de/\n",
" - Either `pip install --user pandas seaborn` once in a shell and `cp $PROJECT_cjsc/herten1/pandas/notebook.ipynb ~/`\n",
" - Or \n",
" 1. `ln -s $PROJECT_cjsc/herten1/pandas ~/.local/share/jupyter/kernels/` and \n",
" 2. `cp $PROJECT_cjsc/herten1/pandas/notebook-with-kernel.ipynb ~/`"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## About Pandas\n",
"\n",
"<img style=\"float: right; max-width: 200px;\" width=\"200px\" src=\"img/adorable-animal-animal-photography-1661535.jpg\" />\n",
"\n",
"* For data analysis\n",
"* With data structures (multi-dimensional table; time series), operations\n",
"* Name from »**Pan**el **Da**ta« (multi-dimensional time series in economics)\n",
"* Since 2008\n",
"* https://pandas.pydata.org/\n",
"* Install [via PyPI](https://pypi.org/project/pandas/): `pip install pandas`"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"\n",
"* Pandas works great together with other established Python tools\n",
" * [Jupyter Notebooks](https://jupyter.org/)\n",
" * Plotting with [`matplotlib`](https://matplotlib.org/)\n",
" * Modelling with [`statsmodels`](https://www.statsmodels.org/stable/index.html), [`scikit-learn`](https://scikit-learn.org/)\n",
" * Nicer plots with [`seaborn`](https://seaborn.pydata.org/), [`altair`](https://altair-viz.github.io/), [`plotly`](https://plot.ly/)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## First Steps"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import pandas"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import pandas as pd"
]
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'0.24.1'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.__version__"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mClass docstring:\u001b[0m\n",
" pandas - a powerful data analysis and manipulation library for Python\n",
" =====================================================================\n",
" \n",
" **pandas** is a Python package providing fast, flexible, and expressive data\n",
" structures designed to make working with \"relational\" or \"labeled\" data both\n",
" easy and intuitive. It aims to be the fundamental high-level building block for\n",
" doing practical, **real world** data analysis in Python. Additionally, it has\n",
" the broader goal of becoming **the most powerful and flexible open source data\n",
" analysis / manipulation tool available in any language**. It is already well on\n",
" its way toward this goal.\n",
" \n",
" Main Features\n",
" -------------\n",
" Here are just a few of the things that pandas does well:\n",
" \n",
" - Easy handling of missing data in floating point as well as non-floating\n",
" point data.\n",
" - Size mutability: columns can be inserted and deleted from DataFrame and\n",
" higher dimensional objects\n",
" - Automatic and explicit data alignment: objects can be explicitly aligned\n",
" to a set of labels, or the user can simply ignore the labels and let\n",
" `Series`, `DataFrame`, etc. automatically align the data for you in\n",
" computations.\n",
" - Powerful, flexible group by functionality to perform split-apply-combine\n",
" operations on data sets, for both aggregating and transforming data.\n",
" - Make it easy to convert ragged, differently-indexed data in other Python\n",
" and NumPy data structures into DataFrame objects.\n",
" - Intelligent label-based slicing, fancy indexing, and subsetting of large\n",
" data sets.\n",
" - Intuitive merging and joining data sets.\n",
" - Flexible reshaping and pivoting of data sets.\n",
" - Hierarchical labeling of axes (possible to have multiple labels per tick).\n",
" - Robust IO tools for loading data from flat files (CSV and delimited),\n",
" Excel files, databases, and saving/loading data from the ultrafast HDF5\n",
" format.\n",
" - Time series-specific functionality: date range generation and frequency\n",
" conversion, moving window statistics, moving window linear regressions,\n",
" date shifting and lagging, etc."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%pdoc pd"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## DataFrames\n",
"### It's all about DataFrames\n",
"\n",
"* Main data containers of Pandas\n",
" - Linear: `Series`\n",
" - Multi Dimension: `DataFrame`\n",
"* `Series` is *only* special case of `DataFrame`\n",
"* → Talk about `DataFrame`s, mention some special `Series` cases"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## DataFrames\n",
"### Construction\n",
"\n",
"* To show features of `DataFrame`, let's construct one!\n",
"* Many construction possibilities\n",
" - From lists, dictionaries, `numpy` objects\n",
" - From CSV, HDF5, JSON, Excel, HTML, fixed-width files\n",
" - From pickled Pandas data\n",
" - From clipboard\n",
" - *From Feather, Parquest, SAS, SQL, Google BigQuery, STATA*"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## DataFrames\n",
"\n",
"### Examples, finally"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"source": [
"ages = [41, 56, 56, 57, 39, 59, 43, 56, 38, 60]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>59</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>43</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>38</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>60</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0\n",
"0 41\n",
"1 56\n",
"2 56\n",
"3 57\n",
"4 39\n",
"5 59\n",
"6 43\n",
"7 56\n",
"8 38\n",
"9 60"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.DataFrame(ages)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>56</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0\n",
"0 41\n",
"1 56\n",
"2 56"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_ages = pd.DataFrame(ages)\n",
"df_ages.head(3)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"* Let's add names to ages; put everything into a `dict()`"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Names': ['Liu', 'Rowland', 'Rivers', 'Waters', 'Rice', 'Fields', 'Kerr', 'Romero', 'Davis', 'Hall'], 'Ages': [41, 56, 56, 57, 39, 59, 43, 56, 38, 60]}\n"
]
}
],
"source": [
"data = {\n",
" \"Names\": [\"Liu\", \"Rowland\", \"Rivers\", \"Waters\", \"Rice\", \"Fields\", \"Kerr\", \"Romero\", \"Davis\", \"Hall\"],\n",
" \"Ages\": ages\n",
"}\n",
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Names</th>\n",
" <th>Ages</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Liu</td>\n",
" <td>41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Rowland</td>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Rivers</td>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Waters</td>\n",
" <td>57</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Names Ages\n",
"0 Liu 41\n",
"1 Rowland 56\n",
"2 Rivers 56\n",
"3 Waters 57"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample = pd.DataFrame(data)\n",
"df_sample.head(4)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Two columns now; one for names, one for ages"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Names', 'Ages'], dtype='object')"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample.columns"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"* `DataFrame` always have indexes; auto-generated or custom"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RangeIndex(start=0, stop=10, step=1)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample.index"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Make `Names` be index with `.set_index()`\n",
"* `inplace=True` will modifiy the parent frame (*I don't like it*)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Ages</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Names</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Liu</th>\n",
" <td>41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rowland</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rivers</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Waters</th>\n",
" <td>57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rice</th>\n",
" <td>39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fields</th>\n",
" <td>59</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Kerr</th>\n",
" <td>43</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Romero</th>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Davis</th>\n",
" <td>38</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Hall</th>\n",
" <td>60</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Ages\n",
"Names \n",
"Liu 41\n",
"Rowland 56\n",
"Rivers 56\n",
"Waters 57\n",
"Rice 39\n",
"Fields 59\n",
"Kerr 43\n",
"Romero 56\n",
"Davis 38\n",
"Hall 60"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample.set_index(\"Names\", inplace=True)\n",
"df_sample"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"* Some more operations"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Ages</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>10.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>50.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>9.009255</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>38.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>41.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>56.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>56.750000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>60.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Ages\n",
"count 10.000000\n",
"mean 50.500000\n",
"std 9.009255\n",
"min 38.000000\n",
"25% 41.500000\n",
"50% 56.000000\n",
"75% 56.750000\n",
"max 60.000000"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample.describe()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Names</th>\n",
" <th>Liu</th>\n",
" <th>Rowland</th>\n",
" <th>Rivers</th>\n",
" <th>Waters</th>\n",
" <th>Rice</th>\n",
" <th>Fields</th>\n",
" <th>Kerr</th>\n",
" <th>Romero</th>\n",
" <th>Davis</th>\n",
" <th>Hall</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Ages</th>\n",
" <td>41</td>\n",
" <td>56</td>\n",
" <td>56</td>\n",
" <td>57</td>\n",
" <td>39</td>\n",
" <td>59</td>\n",
" <td>43</td>\n",
" <td>56</td>\n",
" <td>38</td>\n",
" <td>60</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Names Liu Rowland Rivers Waters Rice Fields Kerr Romero Davis Hall\n",
"Ages 41 56 56 57 39 59 43 56 38 60"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample.T"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Liu', 'Rowland', 'Rivers', 'Waters', 'Rice', 'Fields', 'Kerr',\n",
" 'Romero', 'Davis', 'Hall'],\n",
" dtype='object', name='Names')"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_sample.T.columns"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"* Also: Arithmetic operations"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Ages</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Names</th>\n",