数据分析之Pandas-05数据加载
来源:互联网 发布:江苏旅游大数据 编辑:程序博客网 时间:2024/06/07 11:45
01-读取文本格式数据
pandas提供了一些用于将表格型数据读取为DataFrame对象的函数
02-最常用
read_csv:从文件中加载带分隔符的数据,默认分隔符为逗号
read_table:从文件中加载带分隔符的数据,默认分隔符为制表符
03-读取数据库数据
导包import pandas as pdimport sqlite3读取数据con = sqlite3.connect("../data/weather_2012.sqlite")df = pd.read_sql("SELECT * from weather_2012 LIMIT 3", con)df设置index_coldf = pd.read_sql("SELECT * from weather_2012 LIMIT 3", con, index_col='id')df写数据weather_df = pd.read_csv('../data/weather_2012.csv')con = sqlite3.connect("../data/test_db.sqlite")con.execute("DROP TABLE IF EXISTS weather_2017")weather_df.to_sql("weather_2017", con)
04-读取网络数据
url = 'https://raw.githubusercontent.com/datasets/investor-flow-of-funds-us/master/data/weekly.csv'pd.read_csv(url)
05-什么是数据透视表
数据透视表(Pivot Table)是一种交互式的表,可以进行某些计算,如求和与计数等。所进行的计算与数据跟数据透视表中的排列有关。
之所以称为数据透视表,是因为可以动态地改变它们的版面布置,以便按照不同方式分析数据,也可以重新安排行号、列标和页字段。每一次改变版面布置时,数据透视表会立即按照新的布置重新计算数据。另外,如果原始数据发生更改,则可以更新数据透视表。
06-透视表和交叉表
透视表
行分组透视表df = DataFrame({'size':np.random.randn(4), 'height':np.random.randn(4), 'weight':np.random.randn(4), 'smoke':['No','Yes','No','Yes'], 'sex':['male','female','female','male']})df2 = df.pivot_table(index = ['smoke'])列分组透视表df = DataFrame({'size':np.random.randn(4), 'height':np.random.randn(4), 'weight':np.random.randn(4), 'smoke':['No','Yes','No','Yes'], 'sex':['male','female','male','female']})df2 = df.pivot_table(columns = ['smoke'])行列分组透视表df = DataFrame({'size':np.random.randn(4), 'height':np.random.randint(10,size = 4), 'weight':np.random.randn(4), 'smoke':['No','Yes','No','Yes'], 'sex':['male','female','female','female']})df2 = df.pivot_table(index = 'sex',columns = 'smoke',aggfunc= sum,fill_value=0)display(df,df2)交叉表df = DataFrame({'gender':['male','female','female','male','male','female','female','female','male','female'], 'hand':['left','right','right','right','right','right','left','right','right','right']})display(df,pd.crosstab(df.gender,df.hand,margins=True))数据:hand left right Allgender female 1 5 6male 1 3 4All 2 8 10
07-数据获取地址
https://www.data.gov/
阅读全文
0 0
- 数据分析之Pandas-05数据加载
- Python之pandas数据加载、存储
- python数据分析之(3)pandas
- Python数据分析之pandas学习
- python数据分析之pandas包
- Python数据分析之pandas基础
- Python数据分析之pandas统计分析
- 数据分析之Pandas——数据结构
- Python数据分析之pandas学习
- 数据分析之Pandas-03绘图函数
- Python数据分析之pandas学习
- Python数据分析之pandas ,part1
- Python数据分析之pandas学习
- pandas 数据分析入门
- Pandas数据分析基础
- python数据分析---Pandas
- Python 数据分析 pandas
- Pandas数据特征分析
- 第九周——项目三—用二叉树遍历思想解决问题
- 堆栈和内存分配
- 【bzoj1068】[SCOI2007]压缩
- jQuery之DOM操作详细
- LintCode_212_空格替换
- 数据分析之Pandas-05数据加载
- 自定义TextView,在values下面新建attrs.xml,布局,重写方法
- 解决:“无法打开虚拟机,该虚拟机似乎正在被使用”
- redhat-learn
- 十月英语
- 2017年福州CCF CCSP参赛体会
- Unity5使用所遇难点及解决方案(基于与unity4的比较)(三.管理状态)
- tensorflow学习二:概念知识和一个帮助理解的demo
- 错题3