對不起,基本的問題,但我似乎無法弄清楚。我有以下數據框:在數據框中重複一個元素
df1
a
1 7
2 26
3 32
4 41
...
37 7
38 9
我怎麼會去第37指數在重複值的兩倍,使得下面的生產
df1
a
1 7
2 26
3 32
4 41
...
37 7
38 7
39 9
我試圖用祿來無濟於事:
newp = df1[name].loc[np.repeat(df1.index[-2:].values, 1)] #get the 37th index value to repeat
listofwty[0].loc[36] = newp
listofwty[0].index = listofwty.index+1
@codeninja,'pd.concat([df,df.loc [[37] * 2]])。sort_index()。reset_index(drop = True)' – MaxU
This works!我試圖使用某種插入/附加功能,但是你能解釋這條線的運行方式嗎? – codeninja
@MaxU好評。謝謝。 –