0

I have a list of lists that I want to loop over, each time removing each lists contents and using those contents to filter a dataframe.

for channel,country in params[:1]:
    print(df[(df.channel == channel) & (df.region_sub == country)])

I know the above doesn't work and I believe it's the way I am passing 'channel and 'country' into the loop, but not sure how to correct this.

sample data from params list:

[['on-platform', 'USA'],
 ['on-platform', 'Brazil'],
 ['on-platform', 'Israel']]

I would also like to store the filter dataframe to a new dataframe with a simple naming convention that indexes from df_1 to df_n

The df_n would look like something with date, channel, country as the main attributes. It is essentially just df filtered

madman
  • 153
  • 1
  • 4
  • 16
  • can you share a sample dataframe with expected output. https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – sammywemmy Jan 29 '20 at 05:43
  • What does `df_1` look like, for example? – Sam Chats Jan 29 '20 at 05:43
  • df_1 would just be a filtered down version of df. df is simply date, country, channel, metric as the 4 columns – madman Jan 29 '20 at 05:47
  • The code inside the loop needs to be: `df[(df[channel] == channel) & (df['region_sub'] == country)]` – cs95 Jan 29 '20 at 05:48
  • You may also want to read up on this answer: https://stackoverflow.com/a/50302195/4909087 this question arises from your lack of understanding how to index columns by variables. – cs95 Jan 29 '20 at 05:48

0 Answers0