0

I have a dataframe with say some investment data. I need to extract data from this dataframe based on certain conditions like say funding_type. There are many funding_types available I just need to extract data matching particular fund types.

e.g: funding_type has values venture,seed,angel,equity and so on. I just need data matching funding type say seed and angel

I tried out following

 MF1[MF1['funding_round_type']=='seed']

here MF1 is my dataframe. This gives all the data related to seed fund type

I need condition somewhat like

MF1[MF1['funding_round_type']=='seed' and MF1['funding_round_type']=='angel']

But pandas doesnt allow it.

Any clues?

  • `MF1[(MF1['funding_round_type']=='seed') &(MF1['funding_round_type']=='angel')]` or `MF1[MF1['funding_round_type'].eq('seed') & MF1['funding_round_type'].eq('angel')]` should work – anky Jul 05 '19 at 15:15
  • pandas certainly allows this type of operation, but you have to use the correct syntax. For example: `MF1[MF1['funding_round_type'].isin(['seed','angel'])]` – Brendan Jul 05 '19 at 15:15

1 Answers1

0

And doesn't work here, you would need to use & and likewise for or |, but if you use the expression for the same column, of course it can only have one of the values so with & the expression would be true for none of the columns. You need to use | (or) here:

MF1[(MF1['funding_round_type']=='seed') | (MF1['funding_round_type']=='angel')]

Or as already stated by someone else:

MF1[(MF1['funding_round_type'].isin(['seed', 'angel'])]
jottbe
  • 4,228
  • 1
  • 15
  • 31