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
1
vote
1 answer

how to use pandas isin function in 2d numpy array?

I have created a 2d numpy array with 2 rows and 5 columns. import numpy as np import pandas as pd arr = np.zeros((2, 5)) arr[0] = [12, 94, 4, 4, 2] arr[1] = [1, 3, 4, 12, 46] I have also created a dataframe with two columns col1 and col2 list1 =…
Vesper
  • 795
  • 1
  • 9
  • 21
1
vote
1 answer

check which dates from column 'long_date' are also in array holy_date

i get an empty df although i know some rows should be in it any thoughts how to fix this? the df after the 7th line run looks like this: long_date country 2020-11-07 Portugal 2020-01-01 Portugal the holy_date looks like this:…
student
  • 13
  • 4
1
vote
1 answer

Conditions in python that are not hard-coded

I am trying to find a way to represent conditions for np.where() other than from within the code. In my example below, import pandas as pd import numpy as np file='insert path' df = pd.read_csv(file) df.loc[:, ['col_a','col_b']] = df.loc[:,…
mikecbos
  • 47
  • 6
1
vote
1 answer

Check if substring is in a string in a different DF, if it is then return value from another row

I want to check is a substring from DF1 is in DF2. If it is I want to return a value of a corresponding…
PythonBeginner
  • 463
  • 4
  • 18
1
vote
2 answers

"ValueError: Columns must be same length as key" when filtering dataframe with isin(list)

I am trying to filter a column in my dataframe based on values from a list, here is the snippet of my code where it's going wrong (replaced values for simplicity's sake) import pandas as pd from pandas import…
cdlabs45
  • 107
  • 2
  • 8
1
vote
1 answer

Why .isin() does not work but str.contains() does work for an object column in my pd.DataFrame()

The str.contains() method filters the dataframe to only contain values with "A": df = pd.DataFrame({"City": ["A","B","C","D","A","A"]}) df[df["City"].str.contains("A")] But if I try to use .isin() on the same dataframe the output results in an…
Joe
  • 33
  • 6
1
vote
0 answers

check if multiple conditions exist in row in a dataframe

I have a checklist (.csv) and lots of files (.csv). I want to read files if they are in the checklist. Checklist dataframe has three columns: "Energy": np.int32,"Potential": string ,"Try": np.int32 Files have meaningful names:…
1
vote
1 answer

why is pandas's isin method returning False for matching None?

Suppose i have two equivalent dataframes: df1 = pd.DataFrame({'a': [None, None, None]}) df2 = pd.DataFrame({'a': [None, None, None]}) When i use the isin method as such: df1.isin(df2) I get the following…
Yee Cheng
  • 11
  • 2
1
vote
2 answers

Pandas isin equivalent for float or int

I have a dataframe with column A populated with numbers 1-9. I want to filter just on numbers 2 and 3. isin does not work for float dtypes. Is there an alternative? something similar to: df=df.loc[df['ColA'].isin([2,3])]
fred.schwartz
  • 2,023
  • 4
  • 26
  • 53
1
vote
2 answers

Keeps rows that aren't in list

I have a dataframe with sales and offers. df offer sales 0 £10 off appple 10 1 £10 off apple and samsung 20 I have a list of offers that I want to avoid, which for this example has only 1…
asd
  • 1,245
  • 5
  • 14
1
vote
1 answer

Pandas groupby with isin for consecutive groups

I have a dataframe that looks like the following: arr = pd.DataFrame([[0,0],[0,1],[0,4],[1,4],[1,5],[1,6],[2,5],[2,8],[2,6]) My desired output is booleans that represent whether the value in column 2 is in the next consecutive group or not. The…
lara_toff
  • 413
  • 2
  • 14
1
vote
2 answers

Filter dataframe on second row using list

I have a dataframe that needs to be kept in the structure below. df One two three date apple banana 2019-12-20 0 4 2020-01-03 10 5 Is there a way to keep only columns where the second row is contained…
asd
  • 1,245
  • 5
  • 14
1
vote
1 answer

update column based on matching row values in other columns with condition

I need to replace the value in columns ending in _4 with an updated value based on what value they include in the other columns. if the first 3 columns contain 1, the fourth should be zero. if the first three columns contain zero, then the fourth…
b101
  • 287
  • 1
  • 8
1
vote
2 answers

How Do I Generate a List of Items Not Shared Between Two Dataframes

Basically, I have a single list of a bunch of unique items that are categorized by color (Items). I do some stuff and generate a dataframe with selected combinations of these unique items (Combinations). My goal is to make a list of the items from…
wein3967
  • 45
  • 4
1
vote
5 answers

Pandas count, sum, average specific range/ value for each row

i have big data, i want to count, sum, average for each row only between specific range. df = pd.DataFrame({'id0':[10.3,20,30,50,108,110],'id1':[100.5,0,300,570,400,140], 'id2':[-2.6,-3,5,12,44,53], 'id3':[-100.1,4,6,22,12,42]}) id0 id1 …
1 2
3
9 10