pandas的DataFrame用法
用来生成DataFrame数据
1.说明:
class pandas.
DataFrame
(data=None, index=None, columns=None, dtype=None, copy=False)
Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure.
Parameters: |
data : numpy ndarray (structured or homogeneous), dict, or DataFrame
index : Index or array-like
columns : Index or array-like
dtype : dtype, default None
copy : boolean, default False
|
---|
代码:
1 import tensorflow 2 import lightgbm as lgb 3 import pandas as pd 4 import numpy as np 5 6 class Deng(object): 7 def __init__(self): 8 pass 9 10 def main(self): 11 temp = ['a', 'a', 'b', 'c', 'c'] 12 st = pd.Categorical(temp) 13 print(st) 14 # [a, a, b, c, c] 15 # Categories(3, object): [a, b, c] 16 17 # 遍历temp指出temp中每个字符所属类别的位置索引 18 st2 = st.codes 19 print(st2) 20 # [0 0 1 2 2] 21 22 def gen_data(self): 23 df = pd.DataFrame(data=np.eye(3), columns=['c1', 'c2', 'c3']) 24 print(df) 25 26 27 if __name__ == '__main__': 28 obj = Deng() 29 obj.gen_data()
输出:
c1 c2 c3 0 1.0 0.0 0.0 1 0.0 1.0 0.0 2 0.0 0.0 1.0
转载于:https://www.cnblogs.com/demo-deng/p/9614489.html
pandas的DataFrame用法相关推荐
- pandas.dataframe用法总结 何时返回dataframe 何时返回series
pandas.dataframe用法总结: 1 df[df.Datatype=='train'] 返回的是一个dataframe ,中括号里==返回的为series 它的特点是有索引有值 2 d ...
- panda 函数笔记(merge\DataFrame用法\DataFrame.plot)
1.merge( ) 2.DataFrame用法 2.1.创建一个DataFrame: 2. ...
- 【Python茴香豆系列】之 PANDAS 修改 DataFrame 列名
[Python茴香豆系列]之 PANDAS 修改 DataFrame 列名 用 Python 编程,使用不同的方法来完成同一个目标,有时候是一件很有意思的事情.这让我想起鲁迅笔下的孔乙己.孔乙己对于茴 ...
- python pandas 分类汇总用法_python之pandas用法大全
一.生成数据表 1.首先导入pandas库,一般都会用到numpy库,所以我们先导入备用: import numpy as np import pandas as pd 2.导入CSV或者xlsx文件 ...
- python dataframe 中位数_python下的Pandas中DataFrame基本操作(一),基本函数整理
pandas作者Wes McKinney 在[PYTHON FOR DATA ANALYSIS]中对pandas的方方面面都有了一个权威简明的入门级的介绍,但在实际使用过程中,我发现书中的内容还只是冰 ...
- pandas中DataFrame的ix,loc,iloc索引方式的异同
pandas中DataFrame的ix,loc,iloc索引方式的异同 1.loc: 按照标签索引,范围包括start和end 2.iloc: 在位置上进行索引,不包括end 3.ix: 先在inde ...
- Pandas的DataFrame数据类型
Pandas的DataFrame数据类型 纵轴表示不同索引axis=0,横轴表示不同列axis=1 DataFrame类型创建 1.从二维ndarray对象创建 import pandas as pd ...
- Python—pandas中DataFrame类型数据操作函数
python数据分析工具pandas中DataFrame和Series作为主要的数据结构. 本文主要是介绍如何对DataFrame数据进行操作并结合一个实例测试操作函数. 1)查看DataFram ...
- pandas基于dataframe字符串数据列不包含特定字符串来筛选dataframe中的数据行(rows where values do not contain substring)
pandas基于dataframe字符串数据列不包含(not contains)特定字符串来筛选dataframe中的数据行(rows where values do not contain subs ...
最新文章
- 模板方法模式与策略模式的区别
- php5.0 aes加解密,PHP的aes加解密算法
- supervisor配置环境变量(PATH)
- 【转】3.2SharePoint服务器端对象模型 之 访问文件和文件夹(Part 2)
- nginx之反向代理服务器
- Springboot2拦截器与文件上传
- 成为java gc专家_成为JavaGC专家上(2)—如何监控Java垃圾回收机制
- 开源知识管理系统_Zboot权限后台管理系统开源啦
- solr 使用记录 - solr dataimporter 定时任务
- day47 Pyhton 数据库Mysql 04
- CentOS 7 下挂载NTFS文件系统并实行开机自动挂载
- webpack3 css,webpack3之处理css文件
- python 冒号分隔_以冒号分隔的分析
- C++函数参数省略号
- 学会使用distribute-list过滤路由更新
- WordPress文章发布失败或更新失败解决方法
- 【初创期】企业的安全建设之路到底有多难?
- 如何在CSDN中发布文章
- .RibbonLoadBalancerClient does not define or inherit an implementation of the resolved method
- 2012成都网络赛赛后【缺CHJ】
热门文章
- js 得到select所有option里的值
- 百度网盘文件分享演示,如何查看已经分享的文件
- Spring - IOC常用标签
- 编译器编译16bit单片机程序对数组data[0]=0x12,data[1]=0xBD,data[2]=0x00,data[3]=0x45转换成16进制整数12BD0045的报警
- RTX操作系统库方式移植
- CTFshow 文件上传 web167
- CTFshow php特性 web133
- CTFshow php特性 web115
- Shell 与Python的交互
- condest--1-范数的条件数估计