Создание BOOL col на основе условных критериев [duplicate]

Вы можете использовать эту пользовательскую библиотеку (написанную с помощью Promise) для выполнения удаленного вызова.

function $http(apiConfig) {
    return new Promise(function (resolve, reject) {
        var client = new XMLHttpRequest();
        client.open(apiConfig.method, apiConfig.url);
        client.send();
        client.onload = function () {
            if (this.status >= 200 && this.status < 300) {
                // Performs the function "resolve" when this.status is equal to 2xx.
                // Your logic here.
                resolve(this.response);
            }
            else {
                // Performs the function "reject" when this.status is different than 2xx.
                reject(this.statusText);
            }
        };
        client.onerror = function () {
            reject(this.statusText);
        };
    });
}

Пример простого использования:

$http({
    method: 'get',
    url: 'google.com'
}).then(function(response) {
    console.log(response);
}, function(error) {
    console.log(error)
});
154
задан smci 17 July 2015 в 20:25
поделиться

5 ответов

Вы можете использовать pd.Series.isin .

Для «IN» используйте: something.isin(somewhere)

Или для «NOT IN»: ~something.isin(somewhere)

В качестве обработанного примера:

>>> df
  countries
0        US
1        UK
2   Germany
3     China
>>> countries
['UK', 'China']
>>> df.countries.isin(countries)
0    False
1     True
2    False
3     True
Name: countries, dtype: bool
>>> df[df.countries.isin(countries)]
  countries
1        UK
3     China
>>> df[~df.countries.isin(countries)]
  countries
0        US
2   Germany
350
ответ дан jpp 23 August 2018 в 22:18
поделиться
df = pd.DataFrame({'countries':['US','UK','Germany','China']})
countries = ['UK','China']

реализовать в:

df[df.countries.isin(countries)]

реализовать не так, как в странах покоя:

df[df.countries.isin([x for x in np.unique(df.countries) if x not in countries])]
1
ответ дан Ioannis Nasios 23 August 2018 в 22:18
поделиться

Обычно я делаю общую фильтрацию по строкам следующим образом:

criterion = lambda row: row['countries'] not in countries
not_in = df[df.apply(criterion, axis=1)]
8
ответ дан Kos 23 August 2018 в 22:18
поделиться

Альтернативное решение, использующее метод .query () :

In [5]: df.query("countries in @countries")
Out[5]:
  countries
1        UK
3     China

In [6]: df.query("countries not in @countries")
Out[6]:
  countries
0        US
2   Germany
13
ответ дан MaxU 23 August 2018 в 22:18
поделиться

Я хотел отфильтровать строки dfbc, у которых был BUSINESS_ID, который также был в BUSINESS_ID dfProfilesBusIds

. Наконец, он работал:

dfbc = dfbc[(dfbc['BUSINESS_ID'].isin(dfProfilesBusIds['BUSINESS_ID']) == False)]
1
ответ дан Sam Henderson 23 August 2018 в 22:18
поделиться
Другие вопросы по тегам:

Похожие вопросы: