Python 是否可以在dataframe的两个索引之间添加索引

Python 是否可以在dataframe的两个索引之间添加索引,python,pandas,dataframe,Python,Pandas,Dataframe,“”“是否可以在两行之间添加一行,是否可以在两个索引之间再添加一个索引”“” “获得了预期的输出”您可以添加预期的输出吗?hi@jezrael这不是一个完美的答案,此解决方案正在替换索引值,但我想添加新值而不替换旧值,因此请使用pd.concat([df.iloc[:2],line,df.iloc[3:],ignore_index=True)此解决方案还替换了点上的索引值,df2=pd.concat([df.iloc[:3],line,df.iloc[3:])。reset_index(drop=

“”“是否可以在两行之间添加一行,是否可以在两个索引之间再添加一个索引”“”


“获得了预期的输出”

您可以添加预期的输出吗?hi@jezrael这不是一个完美的答案,此解决方案正在替换索引值,但我想添加新值而不替换旧值,因此请使用
pd.concat([df.iloc[:2],line,df.iloc[3:],ignore_index=True)
此解决方案还替换了点上的索引值,df2=pd.concat([df.iloc[:3],line,df.iloc[3:])。reset_index(drop=True),“df.iloc[3:])。reset_index(drop=True)”这一行放好后,reset_index()应该在那里
import pandas as pd

df = pd.DataFrame({'Age': [30, 40, 30, 40, 30, 30, 20, 25],
                   'Height': [120, 162, 120, 120, 120, 72, 120, 81]})
modDfObj = df.append({'Age' : 25, 'Height':172,} , ignore_index=True) 

modDfObj
import pandas as pd

df = pd.DataFrame({'Age': [30, 40, 30, 40, 30, 30, 20, 25],
                   'Height': [120, 162, 120, 120, 120, 72, 120, 81]},
                  index=['Jane', 'Jane', 'Aaron', 'Penelope', 'Jaane', 'Nicky',
                         'Armour', 'Ponting'])
line = pd.DataFrame({"Age": 33, "Height": 130}, index=[2])
df2 = pd.concat([df.iloc[:2], line, df.iloc[2:]]).reset_index(drop=True)
df2