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 周末祝福语简短有内涵