0

I am trying to filter the rows of a Dataframe depending if the value of a column is part of a series so:

pack_data_clean=pack_data_clean[pack_data_clean["actual_box_barcode"].isin(ref_list)==True] 

Where pack_data_clean is the dataframe to be filtered, actual_box_barcode the column to check and ref_list the series with the values that will remain in the dataframe.

However ref_list is not a regular series with values, but a series made of series, let's see:

ref_list=["BG1", "BG2", "BG3", "BG4", A1_refs, A2_refs, A3_refs, C1_refs, C2_refs, C3_refs, C4_refs, C5_refs , E0_refs, E1_refs, E3_refs, E4_refs, E6_refs, E7_refs, E36_refs] 

Where A1_refs e.g. is:

A1_refs=["EEC", "ENC", "EZC"] 

Right now my code is only filtering the rows that are "BG1", "BG2", "BG3", "BG4" but I would like to filter as well "EEC", "ENC", "EZC" and so on.

Could you please help me to ¡create this filter accordingly? Thanks, Eduardo

1 Answer 1

1

If it's a list of regular objects and series, you need to get it into a consistent series format. This might help:

ref_list = pd.Series(i for i in my_list if type(i) != pd.Series).append(list(j for j in my_list if type(j) == pd.Series)) 

If it's already a Series of Series, try flattening the series before using it, like so:

ref_list = ref_list.ravel() 
Sign up to request clarification or add additional context in comments.

1 Comment

Didn't did the trick, the first one creates another series made of series while ravel doesn't flatten the series as well :S

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.