pandas基本介绍:

import pandas as pd
import numpy as np

s = pd.Series([1, 3, 6, np.nan, 44, 1])
print(s)
"""
0     1.0
1     3.0
2     6.0
3     NaN
4    44.0
5     1.0
dtype: float64
"""

dates = pd.date_range('20190524', periods=6)
print(dates)
"""
DatetimeIndex(['2019-05-24', '2019-05-25', '2019-05-26', '2019-05-27',
               '2019-05-28', '2019-05-29'],
              dtype='datetime64[ns]', freq='D')
"""

df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=['a', 'b', 'c', 'd'])
print(df)
"""
                   a             b           c           d
2019-05-24 -0.241238  0.564423  0.388521 -1.575688
2019-05-25 -0.252545 -0.143675 -0.545198 -0.767073
2019-05-26  0.146703 -1.163519  0.686786 -0.373854
2019-05-27 -0.131501  0.365778  1.225272  0.633931
2019-05-28  0.551303 -0.538687 -0.189405  1.892320
2019-05-29 -0.835084  0.997229 -0.449745 -1.670723
"""

df2 = pd.DataFrame(np.arange(12).reshape((3, 4)))
print(df2)
"""
   0  1   2   3
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11
"""

print(df2.dtypes)
"""
0    int32
1    int32
2    int32
3    int32
dtype: object
"""

print(df2.reindex)
"""
<bound method DataFrame.reindex of    0  1   2   3
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11>
"""

print(df2.describe())  # *重要
"""
         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
"""
最后修改:2019 年 05 月 24 日 03 : 52 PM
如果觉得我的文章对你有用,请随意赞赏