06_handling_dataframe(bool)
In [1]:
import pandas as pd
from collections import OrderedDict
In [2]:
scientists = pd.read_csv("./data/scientists.csv")


boolean 추출과 broadcasting

In [3]:
bool_idx = scientists["Age"] > scientists["Age"].mean()
scientists[bool_idx]
Out[3]:
Name Born Died Age Occupation
1 William Gosset 1876-06-13 1937-10-16 61 Statistician
2 Florence Nightingale 1820-05-12 1910-08-13 90 Nurse
3 Marie Curie 1867-11-07 1934-07-04 66 Chemist
7 Johann Gauss 1777-04-30 1855-02-23 77 Mathematician
In [4]:
## 문자열 2배, 값2배 -- broadcasting
print(scientists*2)
                                       Name                  Born  \
0        Rosaline FranklinRosaline Franklin  1920-07-251920-07-25   
1              William GossetWilliam Gosset  1876-06-131876-06-13   
2  Florence NightingaleFlorence Nightingale  1820-05-121820-05-12   
3                    Marie CurieMarie Curie  1867-11-071867-11-07   
4                Rachel CarsonRachel Carson  1907-05-271907-05-27   
5                        John SnowJohn Snow  1813-03-151813-03-15   
6                    Alan TuringAlan Turing  1912-06-231912-06-23   
7                  Johann GaussJohann Gauss  1777-04-301777-04-30   

                   Died  Age                            Occupation  
0  1958-04-161958-04-16   74                        ChemistChemist  
1  1937-10-161937-10-16  122              StatisticianStatistician  
2  1910-08-131910-08-13  180                            NurseNurse  
3  1934-07-041934-07-04  132                        ChemistChemist  
4  1964-04-141964-04-14  112                    BiologistBiologist  
5  1858-06-161858-06-16   90                    PhysicianPhysician  
6  1954-06-071954-06-07   82  Computer ScientistComputer Scientist  
7  1855-02-231855-02-23  154            MathematicianMathematician  
In [5]:
from IPython.core.display import display, HTML
display(HTML("<style> .container{width:100% !important;}</style>"))

'pandas > basic' 카테고리의 다른 글

07.handling_dataframe(bool-apply)  (0) 2018.12.09
05.handling_series(apply)  (0) 2018.12.09
04.handling_series(basic)  (0) 2018.12.09
03.create_data_frame  (0) 2018.12.09
02.basic_statistic  (0) 2018.12.09

+ Recent posts