3

我想用 2 列参数定位一个数据框:如果我paises_cpm = df.loc[a]正在工作,但如果我这样做,paises_cpm = df.loc[a,b]我会收到一个错误:IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match

import pandas as pd
import time


fecha = time.strftime(str((int(time.strftime("%d")))-1))

subastas = int(fecha) * 5000
impresiones = int(fecha) * 1000

df = pd.read_csv('Cliente_x_Pais.csv')
a = df['Subastas'] > subastas
b = df['Impresiones_exchange'] > impresiones


paises_cpm = df.loc[a,b]

paises_cpm.to_csv('paises_cpm.csv', index=False)
4

1 回答 1

6

|您需要带有foror&for 的链条件and

paises_cpm = df.loc[a | b]

或者:

paises_cpm = df.loc[a & b]

有可能的单行解决方案,但括号是必要的:

paises_cpm = df.loc[(df['Subastas'] > subastas) | 
                    (df['Impresiones_exchange'] > impresiones)
                   ]
于 2018-01-24T13:19:04.533 回答