Questions tagged [isin]

isin is a concept of checking if some value is contained in a list; That concept is used in Python with [pandas] and [numpy]

isin is a concept of checking if some value is contained in a list; That concept is used in Python with [pandas] and [numpy]

147 questions
4
votes
3 answers

Check if a value in one column is in a list in another column using pd.isin()

I have a DataFrame as below df = pd.DataFrame({ 'x' : range(0,5), 'y' : [[0,2],[3,4],[2,3],[3,4],[7,9]] }) I would like to test for each row of x, if the value is in the list specified by column y df[df.x.isin(df.y)] so I would end up…
PingPong
  • 355
  • 2
  • 11
4
votes
2 answers

isin() function using Spark / Java

I have the following two dataframes . dataframe1 ┌────────────┬─────────────┬──────────────┐ │idZones │Longitude │latitude | ├────────────┼─────────────┼──────────────┤ |[50,30,10] |-7.073781666 |33.826661 …
HBoulmi
  • 333
  • 5
  • 16
3
votes
1 answer

Pandas Timestamp and .isin functionality

I am trying to create a function that I will .apply() to a dataframe to: Remove one business day from the provided argument into the function Check to see if this new day is in a specific collection of dates (formatted as a datetime index) I have…
user21584139
3
votes
3 answers

Get a list of rows starting from the same value as current row in pandas dataframe

I have a dataframe that I'd like to expand with a new column which would contain/match the list of all ids if they fully contain the row string_value id string_value 1 The quick brown fox 2 The quick brown fox jumps 3 The quick brown fox…
Nadiia
  • 217
  • 1
  • 7
3
votes
1 answer

Python: Transform ISIN, WKN or RIC to Yahoo Ticker Symbol?

Based on this post here, I have the possibility to transform the ISIN to some form ticker symbol with help of library investpy. This transformation is correct for most of united states stocks. But this symbol itself is not in any case the same as…
Martin Kunze
  • 995
  • 6
  • 16
3
votes
2 answers

Python pandas ISIN with variable

I could use a hand on using the ISIN pandas function. Basically, I need to aggregate data in a dataframe according to different criteria by year. The issue is that I need to do many aggregations on the data (e.g. country name, funding program,…
jsemeano
  • 35
  • 3
3
votes
4 answers

Including null inside PySpark isin

This is my dataframe: from pyspark.sql import SparkSession from pyspark.sql import functions as F spark = SparkSession.builder.getOrCreate() dCols = ['c1', 'c2'] dData = [('a', 'b'), ('c', 'd'), ('e', None)] df =…
ZygD
  • 22,092
  • 39
  • 79
  • 102
3
votes
4 answers

Pandas isin() function is not correctly identifying numerical matches

isin() is giving me weird results. I create the following DataFrame: import pandas as pd import numpy as np test=pd.DataFrame({'1': np.linspace(0.0, 1.0, 11)}) >>> test['1'] 0 0.0 1 0.1 2 0.2 3 0.3 4 0.4 5 0.5 6 0.6 7 …
Gflaesch
  • 41
  • 4
2
votes
2 answers

Pandas isin function in polars

Once in a while I get to the point where I need to run the following line: DF[‘is_flagged’] = DF[‘id’].isin(DF2[DF2[‘flag’]==1][‘id’]) Lately I started using polars, and I wonder how to convert it easily to polars. Edit: For example: df1 =…
Alk90
  • 37
  • 7
2
votes
1 answer

How to use the pandas 'isin' function to give actual values of the df row instead of a boolean expression?

I have two dataframes and I'm comparing their columns labeled 'B'. If the value of column B in df2 matches the value of column B in df1, I want to extract the value of column C from df2 and add it to a new column in df1. Example: df1 df2 Expected…
curd_C
  • 71
  • 2
  • 7
2
votes
5 answers

Pandas: find matching rows in two dataframes (without using `merge`)

Let's suppose I have these two dataframes with the same number of columns, but possibly different number of rows: tmp = np.arange(0,12).reshape((4,3)) df = pd.DataFrame(data=tmp) tmp2 = {'a':[3,100,101], 'b':[4,4,100], 'c':[5,100,3]} df2 =…
ixaixim
  • 83
  • 8
2
votes
1 answer

Python: call pandas_datareader with isin or wkn or translate this into ticker symbol?

I have a real big list of stocks with ISIN and WKN-Number. My aim is to use pandas_datareader to get now historical data from that stocks. My problem is, the function e.g. import pandas_datareader as web stock = web.DataReader('ALB',…
Martin Kunze
  • 995
  • 6
  • 16
2
votes
1 answer

Filtering a dataframe with another dataframe

I got two pandas dataframes. One holds the nodes, the other one holds the edges. As a simple fact: all edges should connect to some node. edges 11 ["INET_N_752", "INET_N_1730"] 253 ["SEQ_5753__L_LMGN", "SEQ_5369__S_LMGN"] 254 …
oakca
  • 1,408
  • 1
  • 18
  • 40
2
votes
1 answer

Numpy element-wise isin for two 2d arrays

I have two arrays: a = np.array([[1, 2], [3, 4], [5, 6]]) b = np.array([[1, 1, 1, 3, 3], [1, 2, 4, 5, 9], [1, 2, 3, 4, 5]]) The expected output would match the shape of array 'a' and would be: array([True, False],…
Zachy
  • 88
  • 5
2
votes
2 answers

Is .isin() faster than .query()

Question: Hi, When searching for methods to make a selection of a dataframe (being relatively unexperienced with Pandas), I had the following question: What is faster for large datasets - .isin() or .query()? Query is somewhat more intuitive to…
Hedge92
  • 543
  • 5
  • 9
1
2 3
9 10