本文实例总结了Python常见的pandas用法。分享给大家供大家参考,具体如下:
0 1.0
1 3.0
2 6.0
3 NaN
4 44.0
5 1.0
dtype: float64
RangeIndex(start=0, stop=6, step=1)
DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04',
'2018-01-05', '2018-01-06'],
dtype='datetime64[ns]', freq='D')
0 1 2 3
0 0 1 2 3
1 4 5 6 7
2 8 9 10 11
a b c d
2018-01-01 0.300675 1.769383 1.244406 -1.058294
2018-01-02 0.832666 2.216755 0.178716 -0.156828
2018-01-03 1.314190 -0.866199 0.836150 1.001026
2018-01-04 -1.671724 1.147406 -0.148676 -0.272555
2018-01-05 1.146664 2.022861 -1.833995 -0.627568
2018-01-06 -0.192242 1.517676 0.756707 0.058869
A B C D E F
0 1.0 2018-01-01 1.0 3 test foo
1 1.0 2018-01-01 1.0 3 train foo
2 1.0 2018-01-01 1.0 3 test foo
3 1.0 2018-01-01 1.0 3 train foo
A float64
B datetime64[ns]
C float32
D int32
E category
F object
dtype: object
Int64Index([0, 1, 2, 3], dtype='int64')
Index(['A', 'B', 'C', 'D', 'E', 'F'], dtype='object')
[[1.0 Timestamp('2018-01-01 00:00:00') 1.0 3 'test' 'foo']
[1.0 Timestamp('2018-01-01 00:00:00') 1.0 3 'train' 'foo']
[1.0 Timestamp('2018-01-01 00:00:00') 1.0 3 'test' 'foo']
[1.0 Timestamp('2018-01-01 00:00:00') 1.0 3 'train' 'foo']]
A C D
count 4.0 4.0 4.0
mean 1.0 1.0 3.0
std 0.0 0.0 0.0
min 1.0 1.0 3.0
25% 1.0 1.0 3.0
50% 1.0 1.0 3.0
75% 1.0 1.0 3.0
max 1.0 1.0 3.0
0 1 2 /
A 1 1 1
B 2018-01-01 00:00:00 2018-01-01 00:00:00 2018-01-01 00:00:00
C 1 1 1
D 3 3 3
E test train test
F foo foo foo
3
A 1
B 2018-01-01 00:00:00
C 1
D 3
E train
F foo
F E D C B A
0 foo test 3 1.0 2018-01-01 1.0
1 foo train 3 1.0 2018-01-01 1.0
2 foo test 3 1.0 2018-01-01 1.0
3 foo train 3 1.0 2018-01-01 1.0
A B C D E F
0 1.0 2018-01-01 1.0 3 test foo
2 1.0 2018-01-01 1.0 3 test foo
1 1.0 2018-01-01 1.0 3 train foo
3 1.0 2018-01-01 1.0 3 train foo
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
2018-01-06 20 21 22 23
2018-01-01 0
2018-01-02 4
2018-01-03 8
2018-01-04 12
2018-01-05 16
2018-01-06 20
Freq: D, Name: A, dtype: int32
2018-01-01 0
2018-01-02 4
2018-01-03 8
2018-01-04 12
2018-01-05 16
2018-01-06 20
Freq: D, Name: A, dtype: int32
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
Empty DataFrame
Columns: [A, B, C, D]
Index: []
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
A B C D
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
A 4
B 5
C 6
D 7
Name: 2018-01-02 00:00:00, dtype: int32
A 8
C 10
Name: 2018-01-03 00:00:00, dtype: int32
A C
2018-01-03 8 10
2018-01-04 12 14
2018-01-05 16 18
A B
2018-01-01 0 1
2018-01-02 4 5
2018-01-03 8 9
2018-01-04 12 13
2018-01-05 16 17
2018-01-06 20 21
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
2018-01-06 20 21 22 23
A 4
B 5
C 6
D 7
Name: 2018-01-02 00:00:00, dtype: int32
5
2018-01-01 1
2018-01-02 5
2018-01-03 9
2018-01-04 13
2018-01-05 17
2018-01-06 21
Freq: D, Name: B, dtype: int32
B C
2018-01-01 1 2
2018-01-02 5 6
2018-01-03 9 10
A C
2018-01-02 4 6
2018-01-04 12 14
2018-01-06 20 22
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
2018-01-06 20 21 22 23
A B C D
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
2018-01-06 20 21 22 23
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
2018-01-06 20 21 22 23
A B C D
2018-01-01 0 1 2 3
2018-01-02 1111 5 6 7
2018-01-03 8 2222 10 11
2018-01-04 12 13 3333 15
2018-01-05 16 17 18 4444
2018-01-06 20 21 22 23
A B C D
2018-01-01 0 -1 2 3
2018-01-02 1111 5 6 7
2018-01-03 8 -1 10 11
2018-01-04 12 13 3333 15
2018-01-05 16 17 18 4444
2018-01-06 20 21 22 23
A B C D
2018-01-01 0 0 0 0
2018-01-02 1111 5 6 7
2018-01-03 0 0 0 0
2018-01-04 12 13 3333 15
2018-01-05 16 17 18 4444
2018-01-06 20 21 22 23
A B C D
2018-01-01 0 1 2 3
2018-01-02 4 5 6 7
2018-01-03 8 9 10 11
2018-01-04 12 13 14 15
2018-01-05 16 17 18 19
2018-01-06 20 21 22 23
A B C D E
2018-01-01 0 1 2 3 NaN
2018-01-02 4 5 6 7 NaN
2018-01-03 8 9 10 11 NaN
2018-01-04 12 13 14 15 NaN
2018-01-05 16 17 18 19 NaN
2018-01-06 20 21 22 23 NaN
A B C D E F
2018-01-01 0 1 2 3 NaN NaN
2018-01-02 4 5 6 7 NaN 1.0
2018-01-03 8 9 10 11 NaN 2.0
2018-01-04 12 13 14 15 NaN 3.0
2018-01-05 16 17 18 19 NaN 4.0
2018-01-06 20 21 22 23 NaN 5.0
A int32
B int32
C int32
D int32
E float64
F float64
dtype: object
A B C D
1 0 NaN 2.0 3
2 4 5.0 NaN 7
3 8 9.0 10.0 11
4 12 13.0 14.0 15
5 16 17.0 18.0 19
6 20 21.0 22.0 23
A B C D
3 8 9.0 10.0 11
4 12 13.0 14.0 15
5 16 17.0 18.0 19
6 20 21.0 22.0 23
A D
1 0 3
2 4 7
3 8 11
4 12 15
5 16 19
6 20 23
A B C D
1 0 NaN NaN 3
2 4 5.0 NaN 7
3 8 9.0 NaN 11
4 12 13.0 NaN 15
5 16 17.0 NaN 19
6 20 21.0 NaN 23
A B D
1 0 NaN 3
2 4 5.0 7
3 8 9.0 11
4 12 13.0 15
5 16 17.0 19
6 20 21.0 23
A B C D
1 0 NaN 2.0 3
2 4 5.0 NaN 7
3 8 9.0 10.0 11
4 12 13.0 14.0 15
5 16 17.0 18.0 19
6 20 21.0 22.0 23
A B C D
1 False True False False
2 False False True False
3 False False False False
4 False False False False
5 False False False False
6 False False False False
A False
B True
C True
D False
dtype: bool
1 True
2 True
3 False
4 False
5 False
6 False
dtype: bool
True
A B C D
1 0 0.0 2.0 3
2 4 5.0 0.0 7
3 8 9.0 10.0 11
4 12 13.0 14.0 15
5 16 17.0 18.0 19
6 20 21.0 22.0 23
id name age gender
0 1 牛帅 23 Male
1 2 gyb 89 Male
2 3 xxs 27 Male
3 4 hey 24 Female
4 5 奥莱利赫本 66 Female
5 6 Jackson 61 Male
6 7 牛帅 23 Male
A B C D
0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0
A B C D
0 1.0 1.0 1.0 1.0
1 1.0 1.0 1.0 1.0
2 1.0 1.0 1.0 1.0
A B C D
0 2.0 2.0 2.0 2.0
1 2.0 2.0 2.0 2.0
2 2.0 2.0 2.0 2.0
A B C D
0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0
0 1.0 1.0 1.0 1.0
1 1.0 1.0 1.0 1.0
2 1.0 1.0 1.0 1.0
0 2.0 2.0 2.0 2.0
1 2.0 2.0 2.0 2.0
2 2.0 2.0 2.0 2.0
A B C D
0 0.0 0.0 0.0 0.0
1 0.0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A B C D
2 1.0 1.0 1.0 1.0
3 1.0 1.0 1.0 1.0
4 1.0 1.0 1.0 1.0
A B C D
1 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0
2 1.0 1.0 1.0 1.0
3 1.0 1.0 1.0 1.0
4 1.0 1.0 1.0 1.0
2 1.0 1.0 1.0 1.0
3 1.0 1.0 1.0 1.0
4 1.0 1.0 1.0 1.0
A B C D E
0 0.0 0.0 0.0 0.0 NaN
1 0.0 0.0 0.0 0.0 NaN
2 0.0 0.0 0.0 0.0 NaN
3 1.0 2.0 3.0 NaN 4.0
A B key
0 A0 B0 K0
1 A1 B1 K1
2 A2 B2 K2
C D key
0 C3 D3 K3
1 C1 D1 K1
2 C2 D2 K2
A B key C D
0 A1 B1 K1 C1 D1
1 A2 B2 K2 C2 D2
A B key C D
0 A0 B0 K0 NaN NaN
1 A1 B1 K1 C1 D1
2 A2 B2 K2 C2 D2
3 NaN NaN K3 C3 D3
A B key C D
0 A0 B0 K0 NaN NaN
1 A1 B1 K1 C1 D1
2 A2 B2 K2 C2 D2
A B key C D
0 A1 B1 K1 C1 D1
1 A2 B2 K2 C2 D2
2 NaN NaN K3 C3 D3
A B key1 key2
0 A0 B0 K0 K0
1 A1 B1 K0 K1
2 A2 B2 K1 K1
C D key1 key2
0 C3 D3 K0 K0
1 C1 D1 K0 K0
2 C2 D2 K1 K1
3 C4 D4 K2 K2
A B key1 key2 C D
0 A0 B0 K0 K0 C3 D3
1 A0 B0 K0 K0 C1 D1
2 A2 B2 K1 K1 C2 D2
A B key1 key2 C D indi
0 A0 B0 K0 K0 C3 D3 both
1 A0 B0 K0 K0 C1 D1 both
2 A1 B1 K0 K1 NaN NaN left_only
3 A2 B2 K1 K1 C2 D2 both
4 NaN NaN K2 K2 C4 D4 right_only
A B
index0 A0 B0
index1 A1 B1
index2 A2 B2
A D
index3 C3 D3
index1 C1 D1
index2 C2 D2
A_x B A_y D
index1 A1 B1 C1 D1
index2 A2 B2 C2 D2
A_b B A_g D
index0 A0 B0 NaN NaN
index1 A1 B1 C1 D1
index2 A2 B2 C2 D2
index3 NaN NaN C3 D3
A_left B A_right D
index0 A0 B0 NaN NaN
index1 A1 B1 C1 D1
index2 A2 B2 C2 D2
index3 NaN NaN C3 D3
A_left B A_right D
index0 A0 B0 NaN NaN
index1 A1 B1 NaN NaN
index2 A2 B2 NaN NaN
index2 NaN index3 C3 D3
index2 NaN index1 C1 D1
index2 NaN index2 C2 D2
A B C
0 -0.399363 -1.004210 0.641141
1 -1.970009 -0.608482 -0.758504
2 -3.081640 -0.617352 -1.143872
3 -2.174627 -1.383785 -1.011411
4 -1.415515 -1.892226 -2.511739
希望本文所述对大家Python程序设计有所帮助。
新闻热点
疑难解答