當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pyspark Index.to_frame用法及代碼示例

本文簡要介紹 pyspark.pandas.Index.to_frame 的用法。

用法:

Index.to_frame(index: bool = True, name: Union[Any, Tuple[Any, …], None] = None) → pyspark.pandas.frame.DataFrame

創建一個DataFrame,其中包含包含索引的列。

參數

index布爾值,默認 True

將返回的DataFrame的索引設置為原始索引。

name對象,默認無

傳遞的名稱應替換索引名稱(如果有的話)。

返回

DataFrame

DataFrame包含原始索引數據。

例子

>>> idx = ps.Index(['Ant', 'Bear', 'Cow'], name='animal')
>>> idx.to_frame()  
       animal
animal
Ant       Ant
Bear     Bear
Cow       Cow

默認情況下,原始索引被重用。要強製執行新索引:

>>> idx.to_frame(index=False)
  animal
0    Ant
1   Bear
2    Cow

要覆蓋結果列的名稱,請指定 name

>>> idx.to_frame(name='zoo')  
         zoo
animal
Ant      Ant
Bear    Bear
Cow      Cow

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Index.to_frame。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。