用来生成DataFrame数据

1.说明:

class pandas.DataFrame(data=Noneindex=Nonecolumns=Nonedtype=Nonecopy=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

Dict can contain Series, arrays, constants, or list-like objects

Changed in version 0.23.0: If data is a dict, argument order is maintained for Python 3.6 and later.

index : Index or array-like

Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided

columns : Index or array-like

Column labels to use for resulting frame. Will default to RangeIndex (0, 1, 2, …, n) if no column labels are provided

dtype : dtype, default None

Data type to force. Only a single dtype is allowed. If None, infer

copy : boolean, default False

Copy data from inputs. Only affects DataFrame / 2d ndarray input

代码:

 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用法相关推荐

  1. pandas.dataframe用法总结 何时返回dataframe 何时返回series

    pandas.dataframe用法总结: 1 df[df.Datatype=='train']  返回的是一个dataframe  ,中括号里==返回的为series 它的特点是有索引有值 2  d ...

  2. panda 函数笔记(merge\DataFrame用法\DataFrame.plot)

    1.merge( )              2.DataFrame用法                       2.1.创建一个DataFrame:                    2. ...

  3. 【Python茴香豆系列】之 PANDAS 修改 DataFrame 列名

    [Python茴香豆系列]之 PANDAS 修改 DataFrame 列名 用 Python 编程,使用不同的方法来完成同一个目标,有时候是一件很有意思的事情.这让我想起鲁迅笔下的孔乙己.孔乙己对于茴 ...

  4. python pandas 分类汇总用法_python之pandas用法大全

    一.生成数据表 1.首先导入pandas库,一般都会用到numpy库,所以我们先导入备用: import numpy as np import pandas as pd 2.导入CSV或者xlsx文件 ...

  5. python dataframe 中位数_python下的Pandas中DataFrame基本操作(一),基本函数整理

    pandas作者Wes McKinney 在[PYTHON FOR DATA ANALYSIS]中对pandas的方方面面都有了一个权威简明的入门级的介绍,但在实际使用过程中,我发现书中的内容还只是冰 ...

  6. pandas中DataFrame的ix,loc,iloc索引方式的异同

    pandas中DataFrame的ix,loc,iloc索引方式的异同 1.loc: 按照标签索引,范围包括start和end 2.iloc: 在位置上进行索引,不包括end 3.ix: 先在inde ...

  7. Pandas的DataFrame数据类型

    Pandas的DataFrame数据类型 纵轴表示不同索引axis=0,横轴表示不同列axis=1 DataFrame类型创建 1.从二维ndarray对象创建 import pandas as pd ...

  8. Python—pandas中DataFrame类型数据操作函数

    python数据分析工具pandas中DataFrame和Series作为主要的数据结构.  本文主要是介绍如何对DataFrame数据进行操作并结合一个实例测试操作函数.  1)查看DataFram ...

  9. pandas基于dataframe字符串数据列不包含特定字符串来筛选dataframe中的数据行(rows where values do not contain substring)

    pandas基于dataframe字符串数据列不包含(not contains)特定字符串来筛选dataframe中的数据行(rows where values do not contain subs ...

最新文章

  1. 模板方法模式与策略模式的区别
  2. php5.0 aes加解密,PHP的aes加解密算法
  3. supervisor配置环境变量(PATH)
  4. 【转】3.2SharePoint服务器端对象模型 之 访问文件和文件夹(Part 2)
  5. nginx之反向代理服务器
  6. Springboot2拦截器与文件上传
  7. 成为java gc专家_成为JavaGC专家上(2)—如何监控Java垃圾回收机制
  8. 开源知识管理系统_Zboot权限后台管理系统开源啦
  9. solr 使用记录 - solr dataimporter 定时任务
  10. day47 Pyhton 数据库Mysql 04
  11. CentOS 7 下挂载NTFS文件系统并实行开机自动挂载
  12. webpack3 css,webpack3之处理css文件
  13. python 冒号分隔_以冒号分隔的分析
  14. C++函数参数省略号
  15. 学会使用distribute-list过滤路由更新
  16. WordPress文章发布失败或更新失败解决方法
  17. 【初创期】企业的安全建设之路到底有多难?
  18. 如何在CSDN中发布文章
  19. .RibbonLoadBalancerClient does not define or inherit an implementation of the resolved method
  20. 2012成都网络赛赛后【缺CHJ】

热门文章

  1. js 得到select所有option里的值
  2. 百度网盘文件分享演示,如何查看已经分享的文件
  3. Spring - IOC常用标签
  4. 编译器编译16bit单片机程序对数组data[0]=0x12,data[1]=0xBD,data[2]=0x00,data[3]=0x45转换成16进制整数12BD0045的报警
  5. RTX操作系统库方式移植
  6. CTFshow 文件上传 web167
  7. CTFshow php特性 web133
  8. CTFshow php特性 web115
  9. Shell 与Python的交互
  10. condest--1-范数的条件数估计