PassengerId 1
Survived 0
Pclass 3
Name Braund, Mr. Owen Harris
Sex male
Age 22
SibSp 1
Parch 0
Ticket A/5 21171
Fare 7.25
Cabin NaN
Embarked S
Name: 0, dtype: object
Cumings, Mrs. John Bradley (Florence Briggs Thayer)
2
1
1
female
38.0
1
0
PC 17599
71.2833
C85
C
Heikkinen, Miss. Laina
3
1
3
female
26.0
0
0
STON/O2. 3101282
1000.0000
NaN
S
Futrelle, Mrs. Jacques Heath (Lily May Peel)
4
1
1
female
35.0
1
0
113803
53.1000
C123
S
Allen, Mr. William Henry
5
0
3
male
35.0
0
0
373450
8.0500
NaN
S
1 2
#bool类型作索引 df['Fare'] > 40
Name
Braund, Mr. Owen Harris False
Cumings, Mrs. John Bradley (Florence Briggs Thayer) True
Heikkinen, Miss. Laina True
Futrelle, Mrs. Jacques Heath (Lily May Peel) True
Allen, Mr. William Henry False
Moran, Mr. James False
McCarthy, Mr. Timothy J True
Palsson, Master. Gosta Leonard False
Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) False
Nasser, Mrs. Nicholas (Adele Achem) False
Sandstrom, Miss. Marguerite Rut False
Bonnell, Miss. Elizabeth False
Saundercock, Mr. William Henry False
Andersson, Mr. Anders Johan False
Vestrom, Miss. Hulda Amanda Adolfina False
Hewlett, Mrs. (Mary D Kingcome) False
Rice, Master. Eugene False
Williams, Mr. Charles Eugene False
Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele) False
Masselmani, Mrs. Fatima False
Fynney, Mr. Joseph J False
Beesley, Mr. Lawrence False
McGowan, Miss. Anna "Annie" False
Sloper, Mr. William Thompson False
Palsson, Miss. Torborg Danira False
Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson) False
Emir, Mr. Farred Chehab False
Fortune, Mr. Charles Alexander True
O'Dwyer, Miss. Ellen "Nellie" False
Todoroff, Mr. Lalio False
...
Giles, Mr. Frederick Edward False
Swift, Mrs. Frederick Joel (Margaret Welles Barron) False
Sage, Miss. Dorothy Edith "Dolly" True
Gill, Mr. John William False
Bystrom, Mrs. (Karolina) False
Duran y More, Miss. Asuncion False
Roebling, Mr. Washington Augustus II True
van Melkebeke, Mr. Philemon False
Johnson, Master. Harold Theodor False
Balkic, Mr. Cerin False
Beckwith, Mrs. Richard Leonard (Sallie Monypeny) True
Carlsson, Mr. Frans Olof False
Vander Cruyssen, Mr. Victor False
Abelson, Mrs. Samuel (Hannah Wizosky) False
Najib, Miss. Adele Kiamie "Jane" False
Gustafsson, Mr. Alfred Ossian False
Petroff, Mr. Nedelio False
Laleff, Mr. Kristo False
Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) True
Shelley, Mrs. William (Imanita Parrish Hall) False
Markun, Mr. Johann False
Dahlberg, Miss. Gerda Ulrika False
Banfield, Mr. Frederick James False
Sutehall, Mr. Henry Jr False
Rice, Mrs. William (Margaret Norton) False
Montvila, Rev. Juozas False
Graham, Miss. Margaret Edith False
Johnston, Miss. Catherine Helen "Carrie" False
Behr, Mr. Karl Howell False
Dooley, Mr. Patrick False
Name: Fare, Length: 891, dtype: bool
1 2
#通过bool类型筛选价格大于40的乘客 df[df['Fare'] > 40][:5]
PassengerId
Survived
Pclass
Sex
Age
SibSp
Parch
Ticket
Fare
Cabin
Embarked
Name
Cumings, Mrs. John Bradley (Florence Briggs Thayer)
data = {'country':['China','America','India'], 'population':[3, 14, 6]} data_df = pd.DataFrame(data) data_df
country
population
0
China
3
1
America
14
2
India
6
1.5 Series操作
1 2 3 4 5 6
#DataFrame和Series都可以看作是二维矩阵,单独的一列就是Series,DataFrame由Series组合 #创建Series data = [11,45,21] index = ['a','b','c'] s = pd.Series(data = data, index = index) s
D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py:3049: DtypeWarning: Columns (12,13,14,15,19,20,81,83,85,87,93,94,95,96,97,98,99,100,105,106,108,109,111,112,114,115,117,118,120,121,123,124,126,127,129,130,132,133,135,136,138,139,141,142,144,145,147,148,150,151,153,154,156,157,160) have mixed types. Specify dtype option on import or set low_memory=False.
interactivity=interactivity, compiler=compiler, result=result)
date
number_of_game
day_of_week
v_name
v_league
v_game_number
h_name
h_league
h_game_number
v_score
...
h_player_7_name
h_player_7_def_pos
h_player_8_id
h_player_8_name
h_player_8_def_pos
h_player_9_id
h_player_9_name
h_player_9_def_pos
additional_info
acquisition_info
0
18710504
0
Thu
CL1
na
1
FW1
na
1
0
...
Ed Mincher
7.0
mcdej101
James McDermott
8.0
kellb105
Bill Kelly
9.0
NaN
Y
1
18710505
0
Fri
BS1
na
1
WS3
na
1
20
...
Asa Brainard
1.0
burrh101
Henry Burroughs
9.0
berth101
Henry Berthrong
8.0
HTBF
Y
2
18710506
0
Sat
CL1
na
2
RC1
na
1
12
...
Pony Sager
6.0
birdg101
George Bird
7.0
stirg101
Gat Stires
9.0
NaN
Y
3
18710508
0
Mon
CL1
na
3
CH1
na
1
12
...
Ed Duffy
6.0
pinke101
Ed Pinkham
5.0
zettg101
George Zettlein
1.0
NaN
Y
4
18710509
0
Tue
BS1
na
2
TRO
na
1
9
...
Steve Bellan
5.0
pikel101
Lip Pike
3.0
cravb101
Bill Craver
6.0
HTBF
Y
5 rows × 161 columns
1
gl.shape
(171907, 161)
1 2
#可以将数值类型向下转换减少内存占用 gl.info(memory_usage = 'deep')
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 171907 entries, 0 to 171906
Columns: 161 entries, date to acquisition_info
dtypes: float64(77), int64(6), object(78)
memory usage: 860.5 MB