I have a sample dataframe like this:
import pandas as pd
sample_df = pd.DataFrame({'color':['red', 'green', 'red', 'red', 'yellow'],
'shape':['circle', 'square', 'rectangle', 'rhombus', 'line']})
And I want to get specific sample row in a new dataframe. I don't get desired output when I try to append dataframe in a for loo
value = ['red', 'green', 'yellow']
df = pd.DataFrame([])
for item in value:
df.append(sample_df[sample_df['color'] == item].sample(1))
df.head()
output : __
How to fix it and only get one each sample of items in the value list?