日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pandas的DataFrame用法

發布時間:2025/4/9 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

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用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。