1

I'm trying to run the following SQL statement (obviously in Python code) in pandas, but am getting nowhere:

select year, contraction, indiv_count, total_words from dataframe
    where contraction in ("i'm","we're","we've","it's","they're")

Where contractions is char, and year, indiv_count, and total_words are int.

I'm not too familiar with pandas. How do I create a similar statement in Python?

blacksite
  • 12,086
  • 10
  • 64
  • 109

1 Answers1

2

I'd recommend reading the docs listed in Anton's comment if you haven't already, but it lacks documentation for the .isin() method which is what you will need to replicate the SQL in.

df[df['contraction'].isin(["i'm","we're","we've","it's","they're"])]

The columns selection can then be obtained using .loc[] or whatever you're favorite method for that is (there are many).

leroyJr
  • 1,110
  • 9
  • 17