I have a large data size. I want to select data for Machine1 and for NorthAmerica. Therefore, if Machine1 and NorthAmerica are in the data series, I want to keep the row.
I know how to do this with one requirement:
df = df[df['MachineNumber'].isin(['Machine1'])]
It works fine and cuts all the data I need. However, I do not know how to do this for two things.
I tried to do this twice, separately like this:
df = df[df['MachineNumber'].isin(['Machine1'])]
df = df[df['Region'].isin(['NorthAmerica'])]
and i also tried
df = df[(df['Region']=='NorthAmerica') & (df['MachineNumber']=='Machine1')]
but both attempts throw an error TypeError: unsupported type for add operationand return an empty framework with column names. I also looked at solutions on the Internet, but they focus on the second solution, but with numbers, not lines. How can I do it right?
An example of data input is a csv called sortingdata.csv with two columns:
Region MachineNumber
EU Machine1
EU Machine1
EU Machine1
EU Machine1
EU Machine1
EU Machine1
EU Machine1
EU Machine1
EU Machine2
NA Machine2
NA Machine2
NA Machine2
NA Machine2
EMEA Machine2
NA Machine2
NA Machine2
NA Machine1
NA Machine1
NA Machine1
NA Machine1
NA Machine1
NA Machine1
NA Machine1
NA Machine1
NA Machine1
and code
import pandas as pd
df = pd.read_csv('sortingdata.csv')
df = df[(df['Region']=='NorthAmerica') & (df['MachineNumber']=='Machine1')]
, Empty DataFrame.