我试图从DataFrame中获取切片并将它们重新组合成一个单独的DF。但是我收到了一个“值”错误,无法从重复的轴重新索引'
run1 = df['run_1']
run2 = df['run_2']
a = run1[305:340]
b = run1[258:270]
c = run2[258:270]
d = run2[305:340]
first_slice = a.combine_first(b)
second_slice = c.combine_first(d)
df1 = pd.DataFrame(first_slice, second_slice)
答案 0 :(得分:0)
您的代码将失败,因为DataFrame
ctor的parmas是:
pandas.DataFrame(data = None,index = None,columns = None,dtype = None, 复制=假)
所以即使它没有抱怨它也不会产生你想要的东西。 joining, merging and concatenating多个dfs有多种方法,在你的情况下concat
就是你想要的:
df1 = pd.concat([first_slice, second_slice])