我有以下DataFrame:
test_data_frame = pd.DataFrame({"cod1":[1,3,5,7],"cod2":[2,4,6,8],"test":["a","b","c","d"]})
我想从“ cod1”下面的“ cod2”列中移动值,像这样在“ test”中保持相同的值:
我现在的解决方案是遍历DataFrame并将新订单保存到字典中:
但这似乎不是最佳解决方案:
new_frame = {"cod":[],"test":[]}
for row in test_data_frame.itertuples():
a,cod1,cod2,test = ((row))
new_frame["cod"].append(cod1)
new_frame["test"].append(test)
new_frame["cod"].append(cod2)
new_frame["test"].append(test)
pd.DataFrame(new_frame)