0

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

1
  • I used newdf = df.loc[df['Name'].isin(namelist)] Commented Jun 29, 2020 at 14:56

2 Answers 2

1

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)]

Sign up to request clarification or add additional context in comments.

Comments

0

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())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.