数据集笔记:分析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的比例

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

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

3 created1 & update

3.1 unix时间戳 转 datetime

python 复制代码
opencellid['created1']=pd.to_datetime(opencellid['created1'],unit='s')
opencellid['updated']=pd.to_datetime(opencellid['updated'],unit='s')
opencellid

3.2 datetime截断到年

python 复制代码
opencellid['created_year'] = opencellid['created1'].dt.year
opencellid['updated_year'] = opencellid['updated'].dt.year
opencellid

3.3 根据年份和radio聚合

python 复制代码
created_grouped = opencellid.groupby(['created_year', 'radio']).size().reset_index(name='count')
created_grouped
python 复制代码
updated_grouped = opencellid.groupby(['updated_year', 'radio']).size().reset_index(name='count')
updated_grouped

3.4 创建数据透视表

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

python 复制代码
created_pivot=created_grouped.pivot(index='created_year',
                      columns='radio',
                      values='count'
                     )
created_pivot
python 复制代码
created_pivot=created_pivot.fillna(0).reset_index()
created_pivot
python 复制代码
updated_pivot=updated_grouped.pivot(index='updated_year',
                      columns='radio',
                      values='count'
                     )
updated_pivot=updated_pivot.fillna(0).reset_index()
updated_pivot

3.5 绘制柱状图

python 复制代码
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")
相关推荐
Jack___Xue几秒前
LangChain实战快速入门笔记(五)--LangChain使用之Tools
笔记·microsoft·langchain
走在路上的菜鸟1 小时前
Android学Dart学习笔记第十三节 注解
android·笔记·学习·flutter
hhy_smile2 小时前
Android 与 java 设计笔记
android·java·笔记
YJlio2 小时前
BgInfo 学习笔记(11.5):多种输出方式(壁纸 / 剪贴板 / 文件)与“更新其他桌面”实战
笔记·学习·c#
断剑zou天涯3 小时前
【算法笔记】线段树SegmentTree
数据结构·笔记·算法
自不量力的A同学3 小时前
ionet 25.2 发布
笔记
YJlio3 小时前
桌面工具学习笔记(11.4):BgInfo + Desktops + ZoomIt 组合拳——演示与排障环境一键到位
笔记·学习·自动化
玩具猴_wjh3 小时前
12.15 学习笔记
笔记·学习
福尔摩斯张4 小时前
TCP协议深度解析:从报文格式到连接管理(超详细)
linux·c语言·网络·c++·笔记·网络协议·tcp/ip
走在路上的菜鸟4 小时前
Android学Dart学习笔记第十四节 库和导库
android·笔记·学习·flutter