I have a dataframe which has 10 000 rows. I need to extract the rows into a new dataframe according to a condition (where name is in name_list)
What is the easiest way to do this
I have a dataframe which has 10 000 rows. I need to extract the rows into a new dataframe according to a condition (where name is in name_list)
What is the easiest way to do this
Let's say this is your dataframe structure and name: dataframe = pd.DataFrame(record, columns = ['Name', 'Age', 'Stream', 'Percentage']
Accordingly, the new dataframe can be created as :
rslt_df = dataframe[dataframe['Name'].isin(name_list)]
alternatively, you can use :
rslt_df = dataframe.loc[dataframe['Name'].isin(name_list)]
U can use for loop to iterate through each rows in the df
for index,row in df.iterrows():
print(row)//row is an array which contain your each column data'[name, age,....]
so you can use your condition in this for loop and filter the rows
or you can use UDF finction to do this by calling df.apply(UDF())