1628人加入学习
(19人评价)
Python数据分析 - Pandas玩转Excel

Python数据分析轻松学

价格 $99美元

任务13:绘制折线趋势图、叠加区域图

!!!!本课下载下来的excel附件名字是Order.xlsx. 编辑代码时注意修改!!!

本课代码:

import pandas as pd
import matplotlib.pyplot as plt

weeks = pd.read_excel('C:/Temp/Orders.xlsx', index_col='Week')
print(weeks)
print(weeks.columns)

#weeks.plot.area(y=['Accessories', 'Bikes', 'Clothing', 'Components', 'Grand Total'])
weeks.plot.bar(y=['Accessories', 'Bikes', 'Clothing', 'Components', 'Grand Total'], stacked=True)
plt.title('Sales Weekly Trend', fontsize=16, fontweight='bold')
plt.ylabel('Total', fontsize=12, fontweight='bold')
plt.xticks(weeks.index, fontsize=8)
plt.show()

打印结果:

       Accessories         Bikes      ...         Components   Grand Total
Week                                  ...                                 
1      9939.465500  2.258337e+06      ...       7.872110e+04  2.356639e+06
2     12626.660000  6.005350e+05      ...       0.000000e+00  6.204234e+05
3     14414.950000  5.547708e+05      ...       0.000000e+00  5.759616e+05
4     12924.580000  5.892557e+05      ...       0.000000e+00  6.083717e+05
5     40443.498516  5.749222e+06      ...       4.709014e+05  6.360041e+06
6     13735.460000  5.539423e+05      ...       0.000000e+00  5.753385e+05
7     13588.800000  6.053847e+05      ...       0.000000e+00  6.247596e+05
8     13997.810000  5.320056e+05      ...       0.000000e+00  5.526938e+05
9     52392.263204  4.701389e+06      ...       6.852023e+05  5.567191e+06
10    14276.640000  5.815496e+05      ...       0.000000e+00  6.037474e+05
11    13584.320000  6.169319e+05      ...       0.000000e+00  6.372021e+05
12    14128.770000  5.985606e+05      ...       0.000000e+00  6.204505e+05
13    34372.148628  5.154563e+06      ...       6.173474e+05  5.899177e+06
14    58097.712659  3.361458e+06      ...       5.296900e+05  4.041540e+06
15    16287.020000  6.655744e+05      ...       0.000000e+00  6.894546e+05
16    15990.960000  6.749113e+05      ...       0.000000e+00  6.991723e+05
17    15120.710000  6.581411e+05      ...       0.000000e+00  6.795171e+05
18    67753.596201  5.739679e+06      ...       1.091392e+06  7.059584e+06
19    15416.040000  7.537814e+05      ...       0.000000e+00  7.770648e+05
20    16113.010000  7.323520e+05      ...       0.000000e+00  7.571492e+05
21    15903.150000  7.380932e+05      ...       0.000000e+00  7.620668e+05
22    57090.139277  4.388471e+06      ...       1.137457e+06  5.746683e+06
23    11900.146000  8.310402e+05      ...       3.152596e+04  8.824418e+05
24    11336.820000  4.095025e+05      ...       0.000000e+00  4.251703e+05
25    10573.210000  4.065446e+05      ...       0.000000e+00  4.232483e+05
26    29376.532664  3.101888e+06      ...       7.994845e+05  4.039316e+06
27    72003.211677  4.932875e+06      ...       1.043760e+06  6.191153e+06
28    11621.900000  4.086479e+05      ...       0.000000e+00  4.258483e+05
29    11640.460000  4.056193e+05      ...       0.000000e+00  4.225788e+05
30    12359.920000  4.156482e+05      ...       0.000000e+00  4.325679e+05
31    81276.364307  5.475372e+06      ...       1.593068e+06  7.363333e+06
32    15208.996500  1.494933e+06      ...       1.025128e+05  1.623856e+06
33    13187.100000  3.938290e+05      ...       0.000000e+00  4.135150e+05
34    13046.980000  4.383911e+05      ...       0.000000e+00  4.571066e+05
35    50187.449516  3.732927e+06      ...       5.842441e+05  4.495606e+06
36    15063.164000  1.173016e+06      ...       6.180437e+04  1.260751e+06
37    11505.920000  4.814773e+05      ...       0.000000e+00  4.985188e+05
38    13170.670000  4.883039e+05      ...       0.000000e+00  5.066807e+05
39    11278.600000  3.675468e+05      ...       0.000000e+00  3.845985e+05
40    70170.520320  7.878476e+06      ...       1.177747e+06  9.303972e+06
41    12441.460000  4.658615e+05      ...       0.000000e+00  4.834701e+05
42    12924.950000  4.715758e+05      ...       0.000000e+00  4.907546e+05
43    13314.310000  4.931541e+05      ...       0.000000e+00  5.127108e+05
44    62745.172581  5.156642e+06      ...       9.100149e+05  6.286165e+06
45    19630.003108  2.199453e+06      ...       1.478740e+05  2.381990e+06
46    14822.180000  7.092621e+05      ...       0.000000e+00  7.304781e+05
47    13728.300000  6.623922e+05      ...       0.000000e+00  6.830832e+05
48    36075.469500  3.240381e+06      ...       2.592590e+05  3.616344e+06
49    13642.418500  1.227307e+06      ...       2.369806e+04  1.273325e+06
50    12388.980000  5.217178e+05      ...       0.000000e+00  5.419306e+05
51    12852.400000  5.264518e+05      ...       0.000000e+00  5.455141e+05
52    13085.680000  5.412245e+05      ...       0.000000e+00  5.604452e+05
53    31315.891268  4.790804e+06      ...       4.568886e+05  5.375680e+06

[53 rows x 5 columns]
Index(['Accessories', 'Bikes', 'Clothing', 'Components', 'Grand Total'], dtype='object')

[展开全文]

授课教师

Tim老师

课程特色

视频(30)
下载资料(25)

学员动态

Adamzyf 加入学习
Marstapeworm 加入学习
alpha 加入学习
elllen 完成了 Code for 002
elllen 开始学习 Code for 002