I have a list of subcategories and a dataframe. I want to filter out the dataframe on the basis of each subcategory of the list.
list = [7774, 29409, 36611, 77553]
import pandas as pd
data = {'aucctlg_id': [143424, 143424, 143424, 143388, 143388, 143430],
'catalogversion_id': [1, 1, 1, 1, 1, 1.2],
'Key': [1434241, 1434241, 1434241, 1433881, 1433881, 14343012],
'item_id': [4501118, 4501130, 4501129, 4501128, 4501127, 4501126],
'catlog_description': ['M&BP PIG IRON FA', 'M&BP PIG IRON FA', 'M&BP PIG IRON FA', 'PIG IRON MIXED OG','PIG IRON MIXED OG', 'P.S JAM & PIG IRON FINES'],
'catlog_start_date': ['17-05-2024 11:00:00', '17-05-2024 11:00:00', '17-05-2024 11:00:00', '17-05-2024 11:00:00','17-05-2024 11:00:00', '17-05-2024 11:00:00'],
'subcategoryid': [29409, 29409, 29409, 7774, 7774, 36611],
'quantity': [200, 200, 200, 180, 180, 100],
'auctionable': ['Y', 'Y', 'Y', 'Y' ,'Y' ,'Y']
}
df = pd.DataFrame(data)
print(df)
I have tried using the following code but I want output as a dataframe here it generates a list and of a single subcategory:
new=[]
for i in range(0,len(list)):
mask1 = df['subcategoryid']==(list[i])
df2 = df.loc[mask1]
new.append(df2)
Required Output files, with the filtered data:
df_7774, df_29409, df_36611