%matplotlib inline
import pandas as pd
import numpy as np
ts = pd.Series(np.random.randn(1000),index=pd.date_range("2000/1/1",periods=1000))
ts = ts.cumsum()
ts.describe()
count 1000.000000
mean 2.404469
std 8.794434
min -18.258983
25% -3.691859
50% 1.319232
75% 9.123154
max 24.196742
dtype: float64
ts.plot(title="cumsum");
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sZdG2caM-1575251389503)(output_2_0.png)]
ts.plot(title="cumsum",linestyle="--",color="r");
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WVk5I7wR-1575251389504)(output_3_0.png)]
ts.plot(title="cumsum",linestyle="-",color="r");
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pbKdoXdY-1575251389504)(output_4_0.png)]
ts.plot(title="cumsum",linestyle="--",color="r",figsize=(8,6));
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Peux3AtL-1575251389504)(output_5_0.png)]
df = pd.DataFrame(np.random.randn(1000,4),index=ts.index,columns=list("ABCD"))
df = df.cumsum()
df.describe()
A | B | C | D | |
---|---|---|---|---|
count | 1000.000000 | 1000.000000 | 1000.000000 | 1000.000000 |
mean | 22.119156 | 14.926277 | 9.414753 | 4.509253 |
std | 14.346089 | 16.009237 | 10.039461 | 9.378749 |
min | -1.148053 | -16.072356 | -17.017132 | -15.367764 |
25% | 9.589624 | -2.476822 | 3.285152 | -2.849600 |
50% | 16.723110 | 23.477262 | 9.601450 | 4.185689 |
75% | 34.131792 | 28.588720 | 15.053845 | 12.145347 |
max | 51.009279 | 39.013864 | 34.634503 | 24.344564 |
df.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1da370746a0>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-R4Lie8nJ-1575251389505)(output_7_1.png)]
df.plot(subplots=True,figsize=(12,6))
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA3741BE48>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA35EF40F0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37182B70>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37143A58>], dtype=object)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cyXuiE7T-1575251389506)(output_8_1.png)]
df.plot(subplots=True,figsize=(12,6),sharey=True)
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37504E80>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA375CB240>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA376340F0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37687BA8>], dtype=object)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kGQOUPwV-1575251389506)(output_9_1.png)]
df["ID"] = np.arange(len(df))
df.describe()
A | B | C | D | ID | |
---|---|---|---|---|---|
count | 1000.000000 | 1000.000000 | 1000.000000 | 1000.000000 | 1000.000000 |
mean | 22.119156 | 14.926277 | 9.414753 | 4.509253 | 499.500000 |
std | 14.346089 | 16.009237 | 10.039461 | 9.378749 | 288.819436 |
min | -1.148053 | -16.072356 | -17.017132 | -15.367764 | 0.000000 |
25% | 9.589624 | -2.476822 | 3.285152 | -2.849600 | 249.750000 |
50% | 16.723110 | 23.477262 | 9.601450 | 4.185689 | 499.500000 |
75% | 34.131792 | 28.588720 | 15.053845 | 12.145347 | 749.250000 |
max | 51.009279 | 39.013864 | 34.634503 | 24.344564 | 999.000000 |
df.plot(x="ID",y=["A","C"])
<matplotlib.axes._subplots.AxesSubplot at 0x1da376c23c8>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kW6m7js4-1575251389507)(output_11_1.png)]
df = pd.DataFrame(np.random.rand(10,4),columns=["A","B","C","D"])
df
A | B | C | D | |
---|---|---|---|---|
0 | 0.444503 | 0.678882 | 0.711676 | 0.872925 |
1 | 0.225838 | 0.493789 | 0.538784 | 0.542961 |
2 | 0.420330 | 0.524319 | 0.508846 | 0.473383 |
3 | 0.331996 | 0.091940 | 0.994004 | 0.853556 |
4 | 0.870556 | 0.029855 | 0.780878 | 0.644138 |
5 | 0.690174 | 0.237141 | 0.863693 | 0.435956 |
6 | 0.683366 | 0.643239 | 0.560769 | 0.666324 |
7 | 0.290208 | 0.216607 | 0.258622 | 0.166087 |
8 | 0.405044 | 0.410000 | 0.177204 | 0.408454 |
9 | 0.992154 | 0.240551 | 0.015421 | 0.108396 |
df.ix[0].plot(kind="bar")
<matplotlib.axes._subplots.AxesSubplot at 0x1da379dd668>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4trCymUP-1575251389508)(output_13_1.png)]
df.plot.bar()
<matplotlib.axes._subplots.AxesSubplot at 0x1da37a1b320>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Yrn695Oj-1575251389509)(output_14_1.png)]
df.plot.bar(stacked=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1da37c1e4a8>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Jdv24zZJ-1575251389509)(output_15_1.png)]
df.plot.barh(stacked=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1da37d892b0>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PvXU8Jra-1575251389510)(output_16_1.png)]
df = pd.DataFrame({"a":np.random.randn(1000)+1,"b":np.random.randn(1000),
"c":np.random.randn(1000)-1},columns = ["a","b","c"])
df
a | b | c | |
---|---|---|---|
0 | 1.508528 | 0.404443 | -0.534487 |
1 | 0.370418 | 1.160731 | -0.217312 |
2 | 1.058697 | -0.027429 | -2.066464 |
3 | 1.063785 | -0.144785 | -0.923300 |
4 | 1.132479 | 0.486729 | -0.115393 |
5 | 2.092360 | -0.752528 | -1.924127 |
6 | 0.153165 | -0.340198 | -0.233272 |
7 | 2.418608 | 1.408432 | -0.687934 |
8 | 0.373591 | -0.418594 | -0.658360 |
9 | 2.532213 | -2.359132 | -0.368593 |
10 | 0.613558 | -1.450630 | -0.674410 |
11 | 2.343465 | 2.872800 | -1.575740 |
12 | -0.189745 | -1.741091 | -2.991217 |
13 | 2.340176 | -0.419048 | -1.078283 |
14 | 1.337136 | -0.407258 | -0.567033 |
15 | 1.069504 | -0.447810 | -0.480902 |
16 | 1.232424 | -0.042300 | -2.126393 |
17 | 1.370300 | 0.103638 | -2.782600 |
18 | 0.170293 | 0.502030 | -1.879367 |
19 | 0.935425 | 1.412264 | -2.285003 |
20 | -0.473395 | 1.218304 | -1.218603 |
21 | 0.411539 | 1.510731 | -0.926930 |
22 | 2.017115 | 1.144694 | -0.870550 |
23 | 3.316523 | -0.113644 | -2.162518 |
24 | 3.876220 | -0.203869 | -0.882337 |
25 | 0.656042 | -0.068283 | -2.105597 |
26 | 0.536914 | 0.336117 | -1.387146 |
27 | 0.676582 | 0.070966 | -2.408016 |
28 | 2.113552 | -1.540061 | 0.260771 |
29 | 1.893816 | -0.578299 | -2.246309 |
... | ... | ... | ... |
970 | 1.379514 | -0.321317 | 0.026253 |
971 | 1.067649 | 0.231581 | -3.067849 |
972 | 1.810218 | 2.071032 | -2.139325 |
973 | 0.403939 | -1.042608 | -1.383304 |
974 | 0.644215 | 1.513606 | -0.905781 |
975 | -0.264936 | -0.190200 | -1.493029 |
976 | 1.630804 | -0.107588 | -2.895967 |
977 | 0.652293 | 0.262708 | 0.888875 |
978 | 1.690942 | 0.772953 | -0.464693 |
979 | 2.511817 | -1.230557 | -2.211896 |
980 | 0.450269 | -2.237094 | 0.999156 |
981 | 1.001377 | 0.639334 | -2.622172 |
982 | 1.981327 | 1.319141 | -1.578372 |
983 | 1.792229 | 0.334895 | -0.446803 |
984 | 2.534870 | 1.592219 | -1.873945 |
985 | 0.793888 | -0.424491 | -1.172793 |
986 | 0.019910 | 0.539585 | -0.293116 |
987 | 0.091286 | 0.983900 | 1.619152 |
988 | 0.419100 | 0.439740 | -2.630594 |
989 | -0.412020 | 1.299779 | -3.382575 |
990 | 0.613458 | 0.292738 | 0.018183 |
991 | 0.896996 | -1.173539 | -0.891172 |
992 | 1.977623 | -1.110332 | -1.626624 |
993 | 2.272282 | -0.766354 | -1.083257 |
994 | 0.749779 | -0.291405 | -1.987565 |
995 | 2.277932 | -0.712442 | -0.899629 |
996 | 1.753836 | 0.034022 | -1.778725 |
997 | 1.154649 | -0.214109 | -0.713381 |
998 | 0.986608 | 1.141246 | -1.220707 |
999 | 0.709445 | -0.386841 | -2.335145 |
1000 rows × 3 columns
df["a"].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x1da37dcee48>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1N6tw8D2-1575251389512)(output_18_1.png)]
df["a"].hist(bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x1da37f56e48>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1olbl4xM-1575251389512)(output_19_1.png)]
df.plot.hist(subplots=True,sharex=True,sharey=True);
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6r6QmZSU-1575251389513)(output_20_0.png)]
df.plot.hist(subplots=True,sharex=True,sharey=True,bins=50);
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-snEPjY3u-1575251389513)(output_21_0.png)]
df.plot.hist()
<matplotlib.axes._subplots.AxesSubplot at 0x1da3960bd68>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M52C4JzX-1575251389514)(output_22_1.png)]
df.plot.hist(alpha=0.3,stacked=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1da3934e978>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-I4ezftXZ-1575251389515)(output_23_1.png)]
df["a"].plot.kde()
<matplotlib.axes._subplots.AxesSubplot at 0x1da3934ec88>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ccQEhOrh-1575251389515)(output_24_1.png)]
df.plot.kde()
<matplotlib.axes._subplots.AxesSubplot at 0x1da396c0d30>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z7fOLLUC-1575251389516)(output_25_1.png)]
df = pd.DataFrame(np.random.rand(10,4),columns=["a","b","c","d"])
df
a | b | c | d | |
---|---|---|---|---|
0 | 0.052313 | 0.737960 | 0.094644 | 0.203991 |
1 | 0.150894 | 0.770775 | 0.818311 | 0.671610 |
2 | 0.325081 | 0.411734 | 0.459532 | 0.500127 |
3 | 0.617931 | 0.200129 | 0.518897 | 0.265602 |
4 | 0.540213 | 0.751956 | 0.871670 | 0.617191 |
5 | 0.088829 | 0.749235 | 0.302258 | 0.933861 |
6 | 0.743885 | 0.218309 | 0.490508 | 0.676424 |
7 | 0.666910 | 0.308370 | 0.426399 | 0.534198 |
8 | 0.459697 | 0.920216 | 0.545206 | 0.976506 |
9 | 0.683433 | 0.613651 | 0.212320 | 0.421099 |
df.plot.scatter(x="a",y="b");
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JZboiMT0-1575251389517)(output_27_0.png)]
s = pd.Series(3*np.random.rand(4),index=["a","b","c","d"],name="series")
s
a 0.462121
b 1.574970
c 1.784554
d 0.822887
Name: series, dtype: float64
s.plot.pie(figsize=(6,6))
<matplotlib.axes._subplots.AxesSubplot at 0x1da39bc4048>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CwNoCwZb-1575251389518)(output_29_1.png)]
s.plot.pie(figsize=(6,6),autopct="%0.2f",fontsize=20,colors=["r","g","b","c"])
<matplotlib.axes._subplots.AxesSubplot at 0x1da39f8dcc0>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TKqigI52-1575251389518)(output_30_1.png)]