我有两个DataFrame,我们把它叫做X和Y,x的维数是2063 x 14,Y的维数是2063 x 8。我想用Y代替X的第4到12列,我能在熊猫上这样做吗?
到目前为止,我找到的解决方案是替换列/多列中的某些值,而不是一次性替换整个DataFrame。感谢你的帮助。(:
发布于 2016-06-30 02:59:45
这应该是可行的:
X.iloc[:, 4:12] = Yiloc和loc允许我们对数据帧进行切片并分配给它们。
# assign Y
# |
# /-\
X.iloc[:, 4:12] = Y
# ^ ^
# | |
# slices |
# all rows |
# slices columns
# 5 through 12
# which constitute
# the 8 columns we want
# replace with the 8
# columns of Yhttps://stackoverflow.com/questions/38112345
复制相似问题