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
相关文章
- pandas-事例练习
- pandas 左右边界切割 用merge join和concat合并Pandas中的数据
- 用Python的pandas框架操作Excel文件中的数据教程
- [Python] Normalize the data with Pandas
- 100天精通Python(数据分析篇)——第72天:Pandas文本数据处理方法之判断类型、去除空白字符、拆分和连接
- 美化 Pandas DataFrame,其实特简单
- Pandas 横向合并DataFrame数据
- 如何优雅的实现pandas DataFrame 和spark dataFrame 相互转换
- 如何迭代pandas dataframe的行
- 【Pandas】Pandas Dataframe 常用用法
- pandas库(Python)
- 【pandas】教程:4-显示数据
- 上手Pandas,带你玩转数据(3)-- pandas数据存入文件
- pandas groupby基本用法