sample based on column pandas

df1 = df[df['a']==1].sample(n=50)
df0 = df[df['a']==0].sample(n=50)
print(pd.concat([df1,df0]))

Here is what the above code is Doing:
1. We’re creating a new dataframe called df1 that contains 50 random rows from df where the value of column ‘a’ is 1.
2. We’re creating a new dataframe called df0 that contains 50 random rows from df where the value of column ‘a’ is 0.
3. We’re concatenating df1 and df0 into a new dataframe called df_new.
4. We’re printing df_new.