pandas的相关知识
数据下载地址:https://download.csdn.net/download/u011730645/10429427
- 数据导入
import pandas as pd
#数据导入
data = pd.read_csv('/home/zhanghanlin/Desktop/test1.csv')
#前五行
first_row = data.head()
print(first_row)
#列的值
print(data.columns)
#矩阵的shape
print(data.shape)
#数据行信息
print(data.loc[0])
前五行:
id birthday name lname sex workday
0 10001 1953/9/2 Georgi Facello M 1986/6/26
1 10002 1964/6/2 Bezalel Simmel F 1985/11/21
2 10003 1959/12/3 Parto Bamford M 1986/8/28
3 10004 1954/5/1 Chirstian Koblick M 1986/12/1
4 10005 1955/1/21 Kyoichi Maliniak M 1989/9/12
列的值:
Index(['id', 'birthday', 'name', 'lname', 'sex', 'workday'], dtype='object')
矩阵的shape:(300024,6)
数据行的信息:
id 10001
birthday 1953/9/2
name Georgi
lname Facello
sex M
workday 1986/6/26
Name: 0, dtype: object
- 切片
#切片包括第6行
data.loc[3:6]
切片的打印:
id birthday name lname sex workday
3 10004 1954/5/1 Chirstian Koblick M 1986/12/1
4 10005 1955/1/21 Kyoichi Maliniak M 1989/9/12
5 10006 1953/4/20 Anneke Preusig F 1989/6/2
6 10007 1957/5/23 Tzvetan Zielinski F 1989/2/10
- 寻找数据流的信息
#寻找数据流的列信息
ndb_col = data['id']
print(ndb_col)
cols = ["id","name"]
print(data[cols])
#寻找数据流的行信息
ndb_row = data.loc(1)
print(ndb_row)
ndb_col:
0 10001
1 10002
2 10003
3 10004
4 10005
5 10006
6 10007
7 10008
8 10009
9 10010
10 10011
11 10012
12 10013
13 10014
14 10015
data[cols]:
id name
0 10001 Georgi
1 10002 Bezalel
2 10003 Parto
3 10004 Chirstian
4 10005 Kyoichi
5 10006 Anneke
6 10007 Tzvetan
7 10008 Saniya
8 10009 Sumant
9 10010 Duangkaew
10 10011 Mary
11 10012 Patricio
12 10013 Eberhardt
13 10014 Berni
14 10015 Guoxiang
- 进行算术运算
#对一列进行算术操作
id_1 = data['id'] / 100
print(id_1)
id_1:
0 100.01
1 100.02
2 100.03
3 100.04
4 100.05
5 100.06
6 100.07
7 100.08
8 100.09
9 100.10
10 100.11
11 100.12
12 100.13
13 100.14
14 100.15
15 100.16
16 100.17
17 100.18
18 100.19
19 100.20
20 100.21
21 100.22
- 数据排序
# 数据排序降序(默认为升序)
data.sort_values('name',inplace=True,ascending=False)
print(data['name'])
data['name']:
152058 Zvonko
211250 Zvonko
86742 Zvonko
149723 Zvonko
29814 Zvonko
125757 Zvonko
12608 Zvonko
110965 Zvonko
29909 Zvonko
46830 Zvonko
222020 Zvonko
164444 Zvonko
36828 Zvonko
30183 Zvonko
166227 Zvonko
273612 Zvonko
6374 Zvonko
74336 Zvonko
237656 Zvonko
128214 Zvonko
204115 Zvonko
204150 Zvonko
182217 Zvonko