当前位置: 首页 > 工具软件 > pythonz > 使用案例 >

Pythonz之pandas

管玉堂
2023-12-01

pandas模块类似于字典形式的numpy

#pandas
import pandas as pd
import numpy as np
s = pd.Series([1,3,6,np.nan,44,1])
print(s)
dates = pd.date_range('20180711',periods=6)
print(dates)
df = pd.DataFrame(np.arange(12).reshape((3,4)))
print(df)
print(df.dtypes)
print(df.index)
print(df.columns)
print(df.values)
print(df.describe())
print(df.T)
print(df.sort_index(axis=1,ascending=False))#对列倒序
# print(df.sort_values(by='2'))对值排序

结果

0     1.0
1     3.0
2     6.0
3     NaN
4    44.0
5     1.0
dtype: float64
DatetimeIndex(['2018-07-11', '2018-07-12', '2018-07-13', '2018-07-14',
               '2018-07-15', '2018-07-16'],
              dtype='datetime64[ns]', freq='D')
   0  1   2   3
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11
0    int32
1    int32
2    int32
3    int32
dtype: object
RangeIndex(start=0, stop=3, step=1)
RangeIndex(start=0, stop=4, step=1)
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]]
         0    1     2     3
count  3.0  3.0   3.0   3.0
mean   4.0  5.0   6.0   7.0
std    4.0  4.0   4.0   4.0
min    0.0  1.0   2.0   3.0
25%    2.0  3.0   4.0   5.0
50%    4.0  5.0   6.0   7.0
75%    6.0  7.0   8.0   9.0
max    8.0  9.0  10.0  11.0
   0  1   2
0  0  4   8
1  1  5   9
2  2  6  10
3  3  7  11
    3   2  1  0
0   3   2  1  0
1   7   6  5  4
2  11  10  9  8
 类似资料: