Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多索引数据帧的布尔索引_Python_Pandas - Fatal编程技术网

Python 多索引数据帧的布尔索引

Python 多索引数据帧的布尔索引,python,pandas,Python,Pandas,假设我有以下几点: X Y A B bar one 0.094315 -0.816244 three -1.316294 -0.383182 flux six -0.176711 0.117511 three -1.401581 1.471682 foo five 0.647646 -0.422405 one

假设我有以下几点:

                   X         Y  
A    B                          
bar  one    0.094315 -0.816244  
     three -1.316294 -0.383182  
flux six   -0.176711  0.117511  
     three -1.401581  1.471682  
foo  five   0.647646 -0.422405  
     one   -0.319071  1.598857  
     two   -0.234279  0.082658  
     two    0.423970  1.418249  
我得到一些布尔序列索引我的数据帧,例如
my_Series=df['X']>0

我想用这个
myu系列
来填写
Y列
上的特定条目。我当然可以:

df[my_series]['Y'] = 1

但这会在视图上写入。如何将基于布尔值的索引与常规标签索引结合起来?

使用
df.loc[df.X>0,'Y']=1

使用
df.loc[df.X>0,'Y']=1