python:pandas模块中的DataFrame结构及常用操作
来源:互联网 发布:mac os sierra 10.13 编辑:程序博客网 时间:2024/06/03 19:33
转载:http://blog.csdn.net/u014607457/article/details/51290582
1. 介绍
DataFrame unifies two or more Series into a single data structure.Each Series then represents a named column of the DataFrame, and instead of each column having its own index, the DataFrame provides a single index and the data in all columns is aligned to the master index of the DataFrame.
这段话的意思是,DataFrame提供的是一个类似表的结构,由多个Series组成,而Series在DataFrame中叫columns
2. 相关操作
a.create
pd.DataFrame()
参数:
1、二维array;
2、Series 列表;
3、value为Series的字典;
a.1、二维array
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
a.2、Series列表(效果与二维array相同)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
a.3、value为Series的字典结构;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
注:若创建使用的参数中,array、Series长度不一样时,对应index的value值若不存在则为NaN
b.属性
b.1 .columns :每个columns对应的keys
b.2 .shape:形状,(a,b),index长度为a,columns数为b
b.3 .index;.values:返回index列表;返回value二维array
b.4 .head();.tail();
c.if-then 操作
c.1使用.ix[]
- 1
- 2
- 3
- 1
- 2
- 3
df.ix[条件,then操作区域]
c.2使用numpy.where
- 1
- 2
- 3
- 1
- 2
- 3
np.where(条件,then,else)
d.根据条件选择取DataFrame
d.1 直接取值df.[]
- 1
- 2
- 3
- 1
- 2
- 3
d.2 使用.loc[]
- 1
- 2
- 3
- 1
- 2
- 3
(还有很多种方法就不一一列举了)
e.Grouping
e.1groupby 形成group
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
e.2 使用get_group 取出其中一分组
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
其他具体操作请参考CookBook
http://pandas.pydata.org/pandas-docs/stable/cookbook.html
0 0
- python:pandas模块中的DataFrame结构及常用操作
- Pandas入门(二)——DataFrame结构及常用操作
- Pandas入门(二)——DataFrame结构及常用操作
- Pandas入门(二)——DataFrame结构及常用操作
- Python Pandas常用数据结构Series和DataFrame的相关操作
- python 中的pandas.DataFrame.fillna
- Python草稿簿-Pandas的DataFrame结构
- python/pandas dataframe中multiindex的操作
- python pandas dataframe 行列选择,切片操作
- Python 数据处理扩展包: pandas 模块的DataFrame介绍(创建和基本操作)
- Python中的pandas模块
- python pandas中series与dataframe数据类型属性及操作基础
- python中pandas包中的DataFrame有关操作iloc与.loc的区别
- Pandas之DataFrame操作
- Pandas之Dataframe操作
- pandas.DataFrame 操作
- Pandas DataFrame操作
- pandas Dataframe操作笔记
- NYOJ_714_Card Trick【队列】
- 币种金额转换
- [SMOJ1781]恐怖电影
- win7下Qt安装调试器
- 网络判断
- python:pandas模块中的DataFrame结构及常用操作
- [转]Ubuntu 16.04 一系列软件安装命令,包括QQ、搜狗、Chrome、vlc、网易云音乐安装方法
- lazyLoading.js懒加载和swiper.js并用
- eazyui小窗口展示
- HTML5 移动Web App阅读器-4(页面基本结构开发)
- poj 1731 Orders(库函数运用)
- 关于js 点击所在行,获取隐藏域问题
- linux内核进程退出分析
- ARC 下的内存泄露