Python - 返回一个表示 Pandas 索引中数据的数组
要返回表示Pandas索引中数据的数组,请使用Pandas中的index.values属性。
首先,导入所需的库-
import pandas as pd
创建索引-
index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])
显示索引-
print("Pandas Index...\n",index)返回一个表示索引中数据的数组-
print("\nArray...\n",index.values)示例
以下是代码-
import pandas as pd
#创建索引
index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])
#显示索引
print("Pandas Index...\n",index)
#返回一个表示索引中数据的数组
print("\nArray...\n",index.values)
#显示索引的转置
print("\nTranspose of the Pandas Index...\n",index.T)输出结果这将产生以下代码-
Pandas Index... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object') Array... ['Car' 'Bike' 'Truck' 'Ship' 'Airplane'] Transpose of the Pandas Index... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object')
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短