简体   繁体   English

将值从一列移动到另一列

[英]move values from one column to another

is there a way to move every second-row value from column 'min' to the 'max' column?有没有办法将第二行的值从“min”列移动到“max”列? In other words, is it possible to move the 'min' column values for TMIN to the corresponding cell in the column on the left?换句话说,是否可以将 TMIN 的“min”列值移动到左侧列中的相应单元格?

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.我正在尝试这个,但是“max”列中的 TMAX 值被“min”列中的值替换,“max”列中的 TMIN 值显示 N/A。

on the picture the max column reflects correct values for TMAX在图片上,最大列反映了 TMAX 的正确值

Would appreciate your help!感谢您的帮助!

Your screen suggests you are using a MultiIndex.您的屏幕提示您正在使用 MultiIndex。

First, you can select rows with 'TMIN' as second level, and then set 'max' column values to 'min' column values for these rows.首先,您可以将“TMIN”作为第二级的 select 行,然后将这些行的“max”列值设置为“min”列值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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