0

I have a dataframe like this:

enter image description here

I'm trying to get the index given the following conditions in the column 'Product':

  • That the value is a string.
  • That the value doesn't contain a comma.

This is what I'm trying now:

product_list = []

for i in data['Product']: 
    if(isinstance(i, str)):
        if "," not in i:
            product_list.append(data['Product'].index)

If the value of the cell is a string, and there isn't a comma, append the index to the list. But I can't get the index this way.

If the condition were easier, just by looking up by one type of product, I could have obtained it this way:

data.index[data['Products']=='A'].tolist()

Is there any similar way to do it?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Jorge
  • 13
  • 3
  • Please don't include images of data, but instead include a text representation of the data, or the code to generate the data to test your code with. https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question – Grismar Sep 29 '21 at 21:57
  • 1
    Perhaps `data[~data.Product.str.contains(",")]`? – hilberts_drinking_problem Sep 29 '21 at 22:11
  • 1
    What do you mean by *If the value of the cell is a string*? A number like 123 in your `Product` column will be a string not a number. – Corralien Sep 29 '21 at 22:28
  • [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – wwii Sep 29 '21 at 23:02

0 Answers0