Skip to main content
Clarrification
Source Link
edualvarado
  • 353
  • 3
  • 13

I am trying to filter a dataframe by column values, but I do not get it. Let suppose I have the following dataframe:

Index Column1 Column2
1      path1   ['red']
2      path2   ['red', 'blue']
3      path3   ['blue']

My dataframe has exactly that format. I want to create a sub-dataframe with the rows containing only ['red'] in Column2. That would be just the first row.

What I tried so far, among other approaches, is:

classes = ['red']
df=df.loc[df['Column2'].isin(classes)]

But it does not work. I get this warning and just remains unchanged:

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison f = lambda x, y: htable.ismember_object(x, values)

How could it done correctly? Thanks.

Edit: I think I did not explain myself very good.

My data, for example ['red' 'blue'] does not have comma in the middle. Is type 'object'. I would like to filter the original dataframe in such a way, it shows the rows with the column 'Column2' containing, for example, red. In that case, it would show me rows 1 and 2. Is that possible?

I am trying to filter a dataframe by column values, but I do not get it. Let suppose I have the following dataframe:

Index Column1 Column2
1      path1   ['red']
2      path2   ['red', 'blue']
3      path3   ['blue']

My dataframe has exactly that format. I want to create a sub-dataframe with the rows containing only ['red'] in Column2. That would be just the first row.

What I tried so far, among other approaches, is:

classes = ['red']
df=df.loc[df['Column2'].isin(classes)]

But it does not work. I get this warning and just remains unchanged:

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison f = lambda x, y: htable.ismember_object(x, values)

How could it done correctly? Thanks.

I am trying to filter a dataframe by column values, but I do not get it. Let suppose I have the following dataframe:

Index Column1 Column2
1      path1   ['red']
2      path2   ['red' 'blue']
3      path3   ['blue']

My dataframe has exactly that format. I want to create a sub-dataframe with the rows containing only ['red'] in Column2. That would be just the first row.

What I tried so far, among other approaches, is:

classes = ['red']
df=df.loc[df['Column2'].isin(classes)]

But it does not work. I get this warning and just remains unchanged:

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison f = lambda x, y: htable.ismember_object(x, values)

How could it done correctly? Thanks.

Edit: I think I did not explain myself very good.

My data, for example ['red' 'blue'] does not have comma in the middle. Is type 'object'. I would like to filter the original dataframe in such a way, it shows the rows with the column 'Column2' containing, for example, red. In that case, it would show me rows 1 and 2. Is that possible?

added 1 character in body
Source Link
jezrael
  • 867.6k
  • 102
  • 1.4k
  • 1.3k

I am trying to filter a dataframe by column values, but I do not get it. Let suppose I have the following dataframe:

Index Column1 Column2
1      path1   ['red']
2      path2   ['red', 'blue']
3      path3   ['blue']

My dataframe has exactly that format. I want to create a sub-dataframe with the rows containing only ['red'] in Column2. That would be just the first row.

What I tried so far, among other approaches, is:

classes = ['red']
df=df.loc[df['Column2'].isin(classes)]

But it does not work. I get this warning and just remains unchanged:

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison f = lambda x, y: htable.ismember_object(x, values)

How could it done correctly? Thanks.

I am trying to filter a dataframe by column values, but I do not get it. Let suppose I have the following dataframe:

Index Column1 Column2
1      path1   ['red']
2      path2   ['red' 'blue']
3      path3   ['blue']

My dataframe has exactly that format. I want to create a sub-dataframe with the rows containing only ['red'] in Column2. That would be just the first row.

What I tried so far, among other approaches, is:

classes = ['red']
df=df.loc[df['Column2'].isin(classes)]

But it does not work. I get this warning and just remains unchanged:

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison f = lambda x, y: htable.ismember_object(x, values)

How could it done correctly? Thanks.

I am trying to filter a dataframe by column values, but I do not get it. Let suppose I have the following dataframe:

Index Column1 Column2
1      path1   ['red']
2      path2   ['red', 'blue']
3      path3   ['blue']

My dataframe has exactly that format. I want to create a sub-dataframe with the rows containing only ['red'] in Column2. That would be just the first row.

What I tried so far, among other approaches, is:

classes = ['red']
df=df.loc[df['Column2'].isin(classes)]

But it does not work. I get this warning and just remains unchanged:

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison f = lambda x, y: htable.ismember_object(x, values)

How could it done correctly? Thanks.

edited tags
Link
cs95
  • 406k
  • 106
  • 744
  • 797
Source Link
edualvarado
  • 353
  • 3
  • 13
Loading