1:A 2:D 3:B 4:C 5:D 6:D 7:C 8:B
(请在问题下面的空白框写出代码并执行以输出结果)
3,4,1,1,3,4,3,3,1,3,2,1,2,1,3,4,1,1,3,4,3,3,1,3,2, 1,2,1,2,3,2,3,1,1,1,1,4,3,1,2,3,2,3,1,1,1,1,4,3,1。
import pandas as pd
pd.set_option('display.max_rows', 8)
data52=pd.read_excel('mydata1.xlsx','5.2');data52
酒类 | |
---|---|
0 | 3 |
1 | 4 |
2 | 1 |
3 | 1 |
... | ... |
46 | 1 |
47 | 4 |
48 | 3 |
49 | 1 |
50 rows × 1 columns
data521=data52.酒类.value_counts();data521
1 20 3 16 2 8 4 6 Name: 酒类, dtype: int64
types=[1,2,3,4]
counts=[20,16,8,6]
data522=pd.DataFrame({'types':types,'counts':counts});data522
types | counts | |
---|---|---|
0 | 1 | 20 |
1 | 2 | 16 |
2 | 3 | 8 |
3 | 4 | 6 |
import matplotlib.pyplot as plt
plt.bar(types,counts); #使用matplotlib绘图系统
import seaborn as sns
sns.barplot(x=types,y=counts,ci=0,palette='Blues_d'); #使用seaborn绘图系统
from plotnine import * #导入plotnine包的绘图函数
from plotnine.data import * #导入plotnine自带的数据集
ggplot(mtcars,aes('wt','mpg',color='factor(gear)'))+geom_point()+stat_smooth(method='lm')+facet_wrap('~gear')
<ggplot: (130549121835)>
ggplot(data522,aes(x='types',y='counts'))+geom_bar(stat='identity')
<ggplot: (130549593703)>
date:日期,单位为月份;
psavert:个人存款率;
pce:个人消费支出,单位为十亿美元;
uemploy:失业人数,单位为千人;
unempmed:失业时间中位数,单位为周;
pop:人口数,单位为千人。
(1)以date为横坐标,unemploy/pop为纵坐标画折线图。
#!pip install pydataset
from plotnine.data import economics
economics
date | pce | pop | psavert | uempmed | unemploy | |
---|---|---|---|---|---|---|
0 | 1967-07-01 | 507.4 | 198712 | 12.5 | 4.5 | 2944 |
1 | 1967-08-01 | 510.5 | 198911 | 12.5 | 4.7 | 2945 |
2 | 1967-09-01 | 516.3 | 199113 | 11.7 | 4.6 | 2958 |
3 | 1967-10-01 | 512.9 | 199311 | 12.5 | 4.9 | 3143 |
... | ... | ... | ... | ... | ... | ... |
570 | 2015-01-01 | 12080.8 | 320367 | 5.5 | 13.4 | 8979 |
571 | 2015-02-01 | 12095.9 | 320534 | 5.7 | 13.1 | 8705 |
572 | 2015-03-01 | 12161.5 | 320707 | 5.2 | 12.2 | 8575 |
573 | 2015-04-01 | 12158.9 | 320887 | 5.6 | 11.7 | 8549 |
574 rows × 6 columns
plt.plot(economics['date'],economics['unemploy']);
plt.plot(economics['date'],economics['pop']);
sns.lineplot(x=economics.date,y=economics.unemploy);
sns.lineplot(x=economics['date'],y=economics['pop']);
ggplot(economics,aes(x='date'))+geom_line(aes(y='unemploy'))
<ggplot: (130549724775)>
ggplot(economics,aes(x='date'))+geom_line(aes(y='pop'))
<ggplot: (130549755516)>
(2)以date为横坐标,unempmed为纵坐标画折线图。
plt.plot(economics.date,economics.uempmed);
sns.lineplot(x=economics.date,y=economics.uempmed);
ggplot(economics,aes(x='date'))+geom_line(aes(y='uempmed'))
<ggplot: (130549829690)>