python
来源:互联网 发布:淘宝上的yizi是正品吗 编辑:程序博客网 时间:2024/06/08 19:46
资料
国家数据 -> 各省年度数据
pandas.melt
实例
import pandas as pddf = pd.read_csv('Data/Region_Data.csv', encoding='gbk', skiprows=3, skipfooter=2, engine='python')df.head()
# df = pd.melt(df, id_vars='地区', value_vars='2015年', col_level=0)df = pd.melt(df, id_vars='地区', col_level=0)
import sqlite3 as dbwith db.connect('country_stat.sqlite') as con: df.to_sql('region_gross_product', con=con, if_exists='replace', index=None)
with db.connect('country_stat.sqlite') as con: sql = 'select * from region_gross_product \ where year=2015 \ order by gross_product \ desc \ limit 10' df2 = pd.read_sql(sql, con=con)
with db.connect('country_stat.sqlite') as con: sql = 'select area, avg(gross_product) as avg_gross_product from region_gross_product \ group by area \ having avg_gross_product >= 10000' #在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用。 df3 = pd.read_sql(sql, con=con)
阅读全文
0 0
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- Android JNI开发(1)--JavaVM和 JNIEnv 动态注册本地方法
- spring boot发送邮件
- fastdfs nginx 搭建分布式文件系统(单机模式)
- 百年携手 砥砺创新 —— 绿色巨人西门子的科技创新与实践之路
- Centos7 yum使用阿里源
- python
- 解决Redis持久化之大数据服务暂停问题
- Tomcat 详解
- 学习总结1
- 数组与矩阵---子矩阵的最大累加和问题
- 如何激活win10家庭版?这个方法超管用
- SpringCloud: 服务链路追踪(Spring Cloud Sleuth)
- FFmpeg源代码分析:libswscale的sws_getContext()
- ArrayList