Slicing A Pandas Dataframe Using Two Strings
I have a large dataframe. I want to select the data that is for Machine1 and for NorthAmerica. So if Machine1 and NorthAmerica is in a row of data, I want to keep the row. I know h
Solution 1:
The code seems to work on your sample data.
# data
# ==================================
df
Region MachineNumber
0 EU Machine1
1 EU Machine1
2 EU Machine1
3 EU Machine1
4 EU Machine1
5 EU Machine1
6 EU Machine1
7 EU Machine1
.. ... ...
17 NA Machine1
18 NA Machine1
19 NA Machine1
20 NA Machine1
21 NA Machine1
22 NA Machine1
23 NA Machine1
24 NA Machine1
[25 rows x 2 columns]
# processing
# ===============================
df[(df['Region']=='NA') & (df['MachineNumber']=='Machine1')]
Region MachineNumber
16 NA Machine1
17 NA Machine1
18 NA Machine1
19 NA Machine1
20 NA Machine1
21 NA Machine1
22 NA Machine1
23 NA Machine1
24 NA Machine1
Post a Comment for "Slicing A Pandas Dataframe Using Two Strings"