数据集笔记:分析OpenCellID 不同radio/ create_time update_time可视化

1 读取数据

(以新加坡的cellID为例)

import geopandas as gpd
import pandas as pd

opencellid=pd.read_csv('OpenCellID_SG.csv',header=None,
            names=['radio','mcc','net','area','cell','unit',
                  'lon','lat','range','samples','changeable1',
                  'created1','updated','AveSignal'])
opencellid

2 不同radio的比例

radio_gather=opencellid.groupby('radio').size()
radio_gather
'''
radio
GSM     10875
LTE     59369
NR        372
UMTS    61726
Name: mcc, dtype: int64
'''
import matplotlib.pyplot as plt

plt.pie(radio_gather,labels=radio_gather.index)

3 created1 & update 

3.1 unix时间戳 转 datetime

opencellid['created1']=pd.to_datetime(opencellid['created1'],unit='s')
opencellid['updated']=pd.to_datetime(opencellid['updated'],unit='s')
opencellid

3.2 datetime截断到年

opencellid['created_year'] = opencellid['created1'].dt.year
opencellid['updated_year'] = opencellid['updated'].dt.year
opencellid

3.3 根据年份和radio聚合

created_grouped = opencellid.groupby(['created_year', 'radio']).size().reset_index(name='count')
created_grouped

updated_grouped = opencellid.groupby(['updated_year', 'radio']).size().reset_index(name='count')
updated_grouped

 

3.4 创建数据透视表

pandas 笔记:pivot_table 数据透视表\pivot_UQI-LIUWJ的博客-CSDN博客

created_pivot=created_grouped.pivot(index='created_year',
                      columns='radio',
                      values='count'
                     )
created_pivot

created_pivot=created_pivot.fillna(0).reset_index()
created_pivot

updated_pivot=updated_grouped.pivot(index='updated_year',
                      columns='radio',
                      values='count'
                     )
updated_pivot=updated_pivot.fillna(0).reset_index()
updated_pivot

3.5 绘制柱状图

from pyecharts.charts import Bar, Grid
from pyecharts import options as opts

bar_created = (
    Bar(init_opts=opts.InitOpts(width='2000px'))
    .add_xaxis(created_pivot['created_year'].astype(str).tolist())
    .add_yaxis("GSM", created_pivot['GSM'].tolist())
    .add_yaxis("LTE", created_pivot['LTE'].tolist())
    .add_yaxis("NR", created_pivot['NR'].tolist())
    .add_yaxis("UMTS", created_pivot['UMTS'].tolist())
    .set_global_opts(title_opts=opts.TitleOpts(title="Count of Created Radio Types per Year"))
)
'''
init_opts=opts.InitOpts(width='2000px') 设置柱状图的宽度
'''

bar_updated = (
    Bar(init_opts=opts.InitOpts(width='2000px'))  # Set chart width
    .add_xaxis(updated_pivot['updated_year'].astype(str).tolist())
    .add_yaxis("GSM", updated_pivot['GSM'].tolist())
    .add_yaxis("LTE", updated_pivot['LTE'].tolist())
    .add_yaxis("NR", updated_pivot['NR'].tolist())
    .add_yaxis("UMTS", updated_pivot['UMTS'].tolist())
    .set_global_opts(title_opts=opts.TitleOpts(title="Count of Updated Radio Types per Year", pos_top="50%"))
)
#pos_top="50%" 设置第二张图title的位置

# Creating a Grid
grid = (
    Grid(init_opts=opts.InitOpts(width='2000px'))
    .add(bar_created, grid_opts=opts.GridOpts(pos_bottom="60%"))
    .add(bar_updated, grid_opts=opts.GridOpts(pos_top="60%"))
)
#两张图叠起来

# Save the grid as a .html file
grid.render("combined_chart.html")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UQI-LIUWJ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值