很抱歉问了个基本问题,但我好像搞不懂。我有以下数据帧:
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
我试过使用loc但没有用:
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
您可以使用^{} 插入另一个37的条目,然后使用^{} 复制该行:
收益率
请注意,这将创建具有非唯一索引的数据帧。制作索引标签 独特的,叫
df = df.reset_index(drop=True)
(作为Scott Boston showed在他的答案)您可以这样做,使用
pd.concat
,然后sort_index
:输出:
相关问题 更多 >
编程相关推荐