向后移动 Pandas DataFrame 一行中的单元格

Shift cells in a row of a Pandas DataFrame backwards

我下面有一个 pandas DataFrame。我想将单元格从 "Undentified" 移回 "Info_1"

以下代码可在您的计算机上重现

df = pd.DataFrame({'Page': {2944: '12344'},
 'Pageviews': {2944: 1.0},
 'Unique Pageviews': {2944: 1.0},
 'Avg. Time on Page': {2944: '0:00:00'},
 'Entrances': {2944: 0.0},
 'Bounce Rate': {2944: '0.00%'},
 '% Exit': {2944: '0.00%'},
 0: {2944: ''},
 1: {2944: 'embed'},
 2: {2944: 'mywebsite'},
 3: {2944: 'product'},
 'ProductType': {2944: '10'},
 'ProductType': {2944: '12'},
 'ProductType': {2944: '15'},
 7: {2944: ''},
 'Info_1': {2944: ''},
 'Info_2': {2944: ''},
 'start': {2944: ''},
 'end': {2944: ''},
 'Age': {2944: ''},
 'Price': {2944: ''},
 14: {2944: ''},
 'Product_typeA': {2944: ''},
 16: {2944: ''},
 "undentified": {2944: '1'},
 18: {2944: '2'},
 19: {2944: '15918400'},
 20: {2944: '15514400'},
 21: {2944: '47'},
 22: {2944: '2200'},
 23: {2944: '15'},
 24: {2944: '3-4'},
 25: {2944: '2'},
 26: {2944: '4'},
 27: {2944: '1'},
 28: {2944: '2'},
 29: {2944: '1'},
 30: {2944: '113&a=5000'}})

这是我将其移回的尝试:

df.loc["Undentified":].shift(-9,axis=1)

不幸的是,这不起作用。它的作用与预期不同。你建议我如何解决这个问题?

您可以使用 shift and transpose(.T)

df2 = df.T.shift(-9, axis=0).T