python pandas dataframe 小结(包括集合set)
来源:互联网 发布:联通在线网络测速 编辑:程序博客网 时间:2024/06/05 14:42
python pandas dataframe 小结(包括集合set)
最近处理一些数据,发现很多坑,踩了之后又忘了又掉坑里,又去找度娘,太低效了。因此花时间总结一下,共勉!!
1.df.shape
df.shape
shape是属性, 并不是函数,返回的是(m*n)的tuple元组
2.python集合set的使用方式:
(1)创建集合:
set1=set()
(2)添加元素:set1.add(i)
#list是append()方法
(3)打印集合:print set1
# 输出结果为带有set字样的:set([1, 2, 3])
(4)将set集合(一列)存入Series中:df=pd.Series(list(set1))
#!!一定要加list,因为集合本身无无序的!~
(5)集合中添加多个list的元素:[set1.add(x) for x in list1]
#一定要加[]!
3.dataframe 查询—iloc
(1)第i行:
df.iloc[i,:]
(2) 第j列:df.iloc[:,j]
(3)第i行j列处的元素:df.iloc[i,j]
(4)前i行:df.iloc[:i,:]
或者df.head(i)
(5)前j列:df.iloc[:,:j]
注意:如果知道列标签名,则查询某一特定列
4.dataframe 增加
(1)添加一行 :
df2.append([[3,3,3]])
(2)添加一列:df2[4]=[4,4,4]
#4 是指的是 列的label
5.dataframe 删除
(1)删除第i行:
df2.drop(i)
#索引是0-n,并不是具体的string串时。
(2)删除某几行:df2.drop([1,2])
#删除索引为1,2的行
(3)删除第j列:df2.drop(0, axis=1)
# 0 是列的lebel~!
(4)删除某几列:df2.drop([0,1],axis=1)
#同上,0,1都是列的lebel~!注意:删除行之后,索引就不是之前那样连续的,可以用reset_index重新排序索引:
df2.reset_index(drop=True)
- python pandas dataframe 小结(包括集合set)
- Pandas.Dataframe使用小结
- Python:Pandas:DataFrame基础(1)
- Python:Pandas:DataFrame基础(2)
- Python:Pandas:DataFrame基础(3)
- python 的pandas DataFrame大全
- python 中的pandas.DataFrame.fillna
- Pandas 数据结构(Series,DataFrame)
- pandas DataFrame 索引(二)
- pandas.dataframe 转换(笔记)
- python:集合(set)
- python 集合(Set)
- python pandas dataframe 去重函数
- python/pandas dataframe中multiindex的操作
- python 数据处理学习pandas之DataFrame(一)
- python 数据处理学习pandas之DataFrame(二)
- python 数据处理学习pandas之DataFrame(三)
- Python之Pandas中Series、DataFrame实践
- Spring的自动装配Bean的三种方式
- 扎实 Javascript 基础 计划
- Virus_LPK专杀
- 移动端meta设置大全
- Spring项目HTTPS
- python pandas dataframe 小结(包括集合set)
- AKKA-源码-dispatcher的构建过程
- Repairing a Road(floyd算法)
- 二叉排序树
- python学习:while循环,输出1到10,除了7
- SQL语句中JOIN的用法
- 算法训练 字符删除
- 线性布局小实现——计算器的简单布局
- Live555源码分析之1