Python自动化办公系列2-数字化经济excel数据可视化
2022-06-27 本文已影响0人
Tony_Pm
序言
天不会一直黑,汗水也不会骗人,时间终会给我们答案。努力从来都不会说谎,它只嘉奖始终坚持的人。你把它放在哪里,哪里就能给你一个不一样的结果。
实战
素材准备
1、安装模块 : pip install pandas
2、excel表格

第一步:读取excel数据
import pandas
### 第一步: 加载文件数据
pd_data = pandas.ExcelFile('数字化经济.xlsx')
sheet_names = pd_data.sheet_names
print(sheet_names)

第二步:提取需要处理的工作表数据
for sheet in sheet_names:
if sheet == '2020年指标':
# 加载数据
pd_df = pandas.read_excel('数字化经济.xlsx',sheet_name=sheet)
print(pd_df)

第三步:把提取的内容处理成可以允许数据可视化图像的数据
pd_df = pd_df.iloc[1:,:]
# 把列修改成表头
pd_df.columns = pd_df.iloc[0:2,:].values[0]
pd_df = pd_df.iloc[1:, :]
# 提取数据
tony_df = pd_df['移动电话基站(万个)']
city = pd_df['地区']
iphone = tony_df.values
iphone_city = city.values
print(iphone,iphone_city)

第四步:数据可视化分析
import matplotlib
import matplotlib.pyplot as plt
font = {'family': 'simhei',
'weight': 'bold',
'size': 5}
matplotlib.rc('font', **font)
# 散点图 x轴 y轴
plt.scatter(iphone_city,iphone,color='Green')
plt.plot(iphone_city,iphone,'red')
# 显示图形
plt.show()
