用来生成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

代码:

 import tensorflow
import lightgbm as lgb
import pandas as pd
import numpy as np class Deng(object):
def __init__(self):
pass def main(self):
temp = ['a', 'a', 'b', 'c', 'c']
st = pd.Categorical(temp)
print(st)
# [a, a, b, c, c]
# Categories(3, object): [a, b, c] # 遍历temp指出temp中每个字符所属类别的位置索引
st2 = st.codes
print(st2)
# [0 0 1 2 2] def gen_data(self):
df = pd.DataFrame(data=np.eye(3), columns=['c1', 'c2', 'c3'])
print(df) if __name__ == '__main__':
obj = Deng()
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

pandas的DataFrame用法的更多相关文章

  1. python 数据处理学习pandas之DataFrame

    请原谅没有一次写完,本文是自己学习过程中的记录,完善pandas的学习知识,对于现有网上资料的缺少和利用python进行数据分析这本书部分知识的过时,只好以记录的形势来写这篇文章.最如果后续工作定下来 ...

  2. Pandas之Dataframe叠加,排序,统计,重新设置索引

    Pandas之Dataframe索引,排序,统计,重新设置索引 一:叠加 import pandas as pd a_list = [df1,df2,df3] add_data = pd.concat ...

  3. pandas中DataFrame对象to_csv()方法中的encoding参数

    当使用pd.read_csv()方法读取csv格式文件的时候,常常会因为csv文件中带有中文字符而产生字符编码错误,造成读取文件错误,在这个时候,我们可以尝试将pd.read_csv()函数的enco ...

  4. pandas(DataFrame)

    DataFrame是二维数据结构,即数据以行和列的表格方式排列!特点:潜在的列是不同的类型,大小可变,标记行和列,可以对列和行执行算数运算. 其中Name,Age即为对应的Columns,序号0,1, ...

  5. Python3 Pandas的DataFrame数据的增、删、改、查

    Python3 Pandas的DataFrame数据的增.删.改.查 一.DataFrame数据准备 增.删.改.查的方法有很多很多种,这里只展示出常用的几种. 参数inplace默认为False,只 ...

  6. Python3 Pandas的DataFrame格式数据写入excle文件、json、html、剪贴板、数据库

    Python3 Pandas的DataFrame格式数据写入excle文件.json.html.剪贴板.数据库 一.DataFrame格式数据 Pandas是Python下一个开源数据分析的库,它提供 ...

  7. python. pandas(series,dataframe,index) method test

    python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...

  8. pandas取dataframe特定行/列

    1. 按列取.按索引/行取.按特定行列取 import numpy as np from pandas import DataFrame import pandas as pd df=DataFram ...

  9. Pandas中DataFrame修改列名

    Pandas中DataFrame修改列名:使用 rename df = pd.read_csv('I:/Papers/consumer/codeandpaper/TmallData/result01- ...

随机推荐

  1. bootstrap -- css -- 表单控件

    若干css样式 .form-control { display: block; width: 100%; height: 34px; padding: 6px 12px; font-size: 14p ...

  2. cake build使用:

    开源地址: https://github.com/cake-build/cake 依赖 powershell 3.0 Windows 获取引导程序: Invoke-WebRequest http:// ...

  3. Oracle查询优化--排序

    --普通排序 SELECT * FROM emp ORDER BY sal DESC; --使用列序排序 DESC; --组合排序 DESC; --translate函数,参数分别用A.B.C表示 S ...

  4. 学习 TList 类的实现[4]

    现在准备一步步地模拟 TList 类, 建立一个自己的 TMyList. 首先, 这个类中应该包括前面提到的那个 Pointer 数组(TPointerList)的指针(PPointerList): ...

  5. 阮一峰---javascript系列

    2013.05.11:如何做到 jQuery-free?(29条评论) 2013.01.23:JavaScript Source Map 详解(14条评论) 2013.01.14:Javascript ...

  6. C#资源释放及Dispose、Close和析构方法

    https://www.cnblogs.com/luminji/archive/2011/01/05/1926468.html C#资源释放及Dispose.Close和析构方法   备注:此文的部分 ...

  7. Entity Framework底层操作封装V2版本号(4)

    这个版本号里面.由于涉及到了多库的操作.原有的系统方法不能做到这种事情了.所以这里有了一点差别 这个类的主要用作就是,连接字符串的作用,默认是指向默认配置里面的,可是你能够指向其它的连接 using ...

  8. mybatis由浅入深day02_3一对多查询

    3 一对多查询 3.1 需求(查询订单及订单明细的信息) 查询订单及订单明细的信息. 3.2 sql语句 确定主查询表:订单表 确定关联查询表:订单明细表 在一对一查询基础上添加订单明细表关联即可. ...

  9. ch6-定制数据对象(打包代码和数据)

    为了看出数据属于哪个选手,教练向各个选手的数据文件中添加了标识数据:选手全名,出生日期,计时数据. 例如:sarah文件的数据更新为: Sarah Sweeney,2002-6-17,2:58,2.5 ...

  10. 第二篇:一个经典的比喻( 关于TCP连接API )

    前言 编程是对现实世界的模拟,网络通信自然也是对现实世界通信的模拟.可以将网络通信中使用的各种API和对现实世界中的各种通信设备进行通讯的操作进行对比以加深理解. 对比 socket() 函数 vs ...