It is simple to choose one row from a Pandas DataFrame however, if I wish to choose numerous rows, my selection criteria are the values that are kept in a list. I must choose rows from Pandas DataFrame using the list of values for this purpose. Here’s how to understand it:
DataFrame:
Name Age City
0 John 25 New York
1 Emily 28 London
2 Michael 30 Paris
3 Jessica 24 Tokyo
List of values:
# List of values to select rows from DataFrame
names_to_select = ['John', 'Michael']
Required Output:
Name Age City
0 John 25 New York
2 Michael 30 Paris
I’m not sure how I can select several rows from a DataFrame using a list of values. Share a way with me if you are aware of one that enables me to choose rows from DataFrama using a list of values.