简体   繁体   中英

move values from one column to another

is there a way to move every second-row value from column 'min' to the 'max' column? In other words, is it possible to move the 'min' column values for TMIN to the corresponding cell in the column on the left?

df['max'].iloc[::1] = df['min'].iloc[::2] 

I'm trying this one, but the TMAX values from the 'max' column get substituted with the values from the 'min' column, and the TMIN values in the 'max' column show N/A.

on the picture the max column reflects correct values for TMAX

Would appreciate your help!

Your screen suggests you are using a MultiIndex.

First, you can select rows with 'TMIN' as second level, and then set 'max' column values to 'min' column values for these rows.

tmins = pd.IndexSlice[:, 'TMIN']
df.loc[tmins, 'max'] = df.loc[tmins, 'min']

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