Having CSV file like this loaded as pandas dataframe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
latitude longitude POLangleWMean POLparticSum 0 10 0 89.326923 5.200 1 -71 6 99.259259 135.000 2 -59 15 81.428571 56260.486 3 -20 24 110.135196 6725.932 4 -49 30 74.014870 4035.000 5 1 31 91.250000 1.600 6 -57 31 87.832512 101972.131 7 17 35 70.789474 1.900 8 -19 39 93.877140 49.650 9 23 46 41.769231 6.500 10 28 47 88.782816 20.950 11 -46 51 73.108108 370.000 12 -48 52 76.363636 11051.167 13 -18 54 115.419355 7.750 14 38 55 31.250000 7.600 15 1 58 83.870968 3.100 16 -57 58 127.500000 6027.909 17 12 64 91.875000 4.800 18 -53 64 60.000000 4018.606 19 -22 64 35.000000 7.900 |
I am interested only in records with latitude>10 and longitude<60. To obtain such a dataframe, we can do
1 |
df[(df.latitude > 10) & (df.longitude <60)] |
Gives us desired data
1 2 3 4 5 |
latitude longitude POLangleWMean POLparticSum 7 17 35 70.789474 1.90 9 23 46 41.769231 6.50 10 28 47 88.782816 20.95 14 38 55 31.250000 7.60 |
However maybe we don't want to hardcode names of used columns and want to stay dynamic. In that case, we can specify column name by string
1 |
df[(df["latitude"] > 10) & (df["longitude"]<60)] |
The way this works underhood is actually just plain masking. You can try to run
1 |
(df.latitude > 10) & (df.longitude <60) |
Gives output of pandas.series type of booleans.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
0 False 1 False 2 False 3 False 4 False 5 False 6 False 7 True 8 False 9 True 10 True 11 False 12 False 13 False 14 True 15 False 16 False 17 False 18 False 19 False dtype: bool |
Therefore, this mask is just in the end just used to mask whether n-th record out of all records should be use or not. If you would like to play with this data along, here are the CSV data to load into pandas
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
latitude,longitude,POLangleWMean,POLparticSum 10.0,0.0,89.3269230769,5.2 -71.0,6.0,99.2592592593,135.0 -59.0,15.0,81.4285714286,56260.486 -20.0,24.0,110.135196008,6725.932 -49.0,30.0,74.0148698885,4035.0 1.0,31.0,91.25,1.6 -57.0,31.0,87.8325123152,101972.131 17.0,35.0,70.7894736842,1.9 -19.0,39.0,93.8771399799,49.65 23.0,46.0,41.7692307692,6.5 28.0,47.0,88.7828162291,20.95 -46.0,51.0,73.1081081081,370.0 -48.0,52.0,76.3636363637,11051.167 -18.0,54.0,115.419354839,7.75 38.0,55.0,31.25,7.6 1.0,58.0,83.8709677419,3.1 -57.0,58.0,127.5,6027.909 12.0,64.0,91.875,4.8 -53.0,64.0,60.0000000001,4018.606 -22.0,64.0,35.0,7.9 |