Python Pandas - 重复索引的元素
要重复索引的元素,请使用Pandas中的方法。将重复次数设置为参数。首先,导入所需的库-index.repeat()
import pandas as pd
创建熊猫索引-
index = pd.Index(['Car','Bike','Airplane', 'Ship','Truck','Suburban'], name ='Transport')
显示熊猫指数-
print("Pandas Index...\n",index)重复索引的元素-
print("\nResult after repeating each index element twice...\n",index.repeat(2))示例
以下是代码-
import pandas as pd
#创建Pandas索引
index = pd.Index(['Car','Bike','Airplane', 'Ship','Truck','Suburban'], name ='Transport')
#显示Pandas索引
print("Pandas Index...\n",index)
#返回索引中的元素数
print("\nNumber of elements in the index...\n",index.size)
#返回数据的dtype
print("\nThe dtype object...\n",index.dtype)
#重复索引元素
print("\nResult after repeating each index element twice...\n",index.repeat(2))输出结果这将产生以下输出-
Pandas Index... Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck', 'Suburban'], dtype='object', name='Transport') Number of elements in the index... 6 The dtype object... object Result after repeating each index element twice... Index(['Car', 'Car', 'Bike', 'Bike', 'Airplane', 'Airplane', 'Ship', 'Ship', 'Truck', 'Truck', 'Suburban', 'Suburban'], dtype='object', name='Transport')
热门推荐
10 文艺结婚祝福语短语简短
11 简短霸气的考试祝福语
12 打牌翻盘祝福语简短
13 送女士祝福语长辈简短
14 好朋友夫妻祝福语简短
15 朋友花篮开业祝福语简短
16 新年酒席开席祝福语简短
17 虎年台词祝福语大全简短
18 中考祝福语简短卡片大全