import os, sys
import numpyt as np
import pandas as pd
读取excel 表格.
res=pd.DataFrame(pd.read_excl(file_name))
res= pd.read_csv
写 excle
res.to_excel(file_name)
res.to_csv(file_name)
>>> s
0 1
1 2
2 3a
3 3b
4 03c
5 我们(无效)
dtype: object
>>> type(s)
找到指定字符的数据
>>> s.str.contains(u'(?=我们).*')
0 False
1 False
2 False
3 False
4 False
5 True
dtype: bool
>>> s[s.str.contains(u'(?=我们).*')]
5 我们(无效)
dtype: object
>>>
>>> s.str.contains(u'无效')
0 False
1 False
2 False
3 False
4 False
5 True
dtype: bool
>>> s[s.str.contains(u'无效')]
5 我们(无效)
dtype: object
>>> import numpy as np
>>> n=10
>>> df = pd.DataFrame(np.random.randint(n, size=(n, 2)), columns=list('bc'))
>>> df
b c
0 1 6
1 3 6
2 0 9
3 2 4
4 7 5
5 7 2
6 9 7
7 1 2
8 3 7
9 3 6
数据查询条件.
>>> df[df['b'] > 5]
b c
4 7 5
5 7 2
6 9 7
列之间比较.
>>> df[df.b > df.c]
b c
4 7 5
5 7 2
6 9 7
从数据集中删除筛选出来的数据集.
>>> df2=df
>>> df2
b c
0 1 6
1 3 6
2 0 9
3 2 4
4 7 5
5 7 2
6 9 7
7 1 2
8 3 7
9 3 6
>>> df3=df[df.b > df.c]
>>> df3
b c
4 7 5
5 7 2
6 9 7
>>> df2.drop(df3.index)
b c
0 1 6
1 3 6
2 0 9
3 2 4
7 1 2
8 3 7
9 3 6
几个数据统计方面的方法.
>>> df2
b c
0 1 6
1 3 6
2 0 9
3 2 4
4 7 5
5 7 2
6 9 7
7 1 2
8 3 7
9 3 6
>>>
>>> df2.groupby(by='b').sum() 求和
c
b
0 9
1 8
2 4
3 19
7 7
9 7
>>> df2.groupby(by='b').count() 计数,
c
b
0 1
1 2
2 1
3 3
7 2
9 1
>>> df2.groupby(by='b').mean() 平均值.
c
b
0 9.000000
1 4.000000
2 4.000000
3 6.333333
7 3.500000
9 7.000000