简体   繁体   中英

Shifting Cells values in Python

I have the following DataFrame:

SampleTable

Hence the header of the table I imported is divided in two cells I need to shift the cells of the first two columns to shift up. And then to shift the 3 and 4 up. For it to look like this:

What I need

I have tried

df.at[1,'x'] = None

But that just deletes de value without shifting any cell.

What I get

Get the header with

df.columns = df.loc[0].iloc[:2].tolist() + df.columns[2:].tolist()
df = df.loc[1:].reset_index(drop=True)
   A  B  C  D
0  1  2  3  4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM