I have a data frame that looks like this:
fips | year | pollutant | nonattainment |
---|---|---|---|
72137 | 1992 | Sulfur Dioxide (1971) | |
72137 | 1992 | PM-2.5 (1997) | P |
72137 | 1992 | 8-Hour Ozone (2015) | W |
72137 | 1992 | 'Nitrogen Dioxide (1971)' | |
72137 | 1993 | Sulfur Dioxide (1971) | |
72137 | 1993 | PM-2.5 (1997) | |
72137 | 1993 | 8-Hour Ozone (2015) | W |
72137 | 1993 | 'Nitrogen Dioxide (1971)' |
FYI:
- The
nonattainment
column has the valueP
orW
- The
pollutant
contains value within this list['PM-2.5 (1997)', 'PM-2.5 (2006)', 'PM-10 (1987)', 'PM-2.5 (2012)']
.
Task:
I now want to add a new column called nonattainment_pm
, which should contain the value 1
; if for any unique fips-year combination,
Expected output:
i.e. the new data frame should look like this:
fips | year | pollutant | nonattainment | nonattainment_pm |
---|---|---|---|---|
72137 | 1992 | Sulfur Dioxide (1971) | 1 | |
72137 | 1992 | PM-2.5 (1997) | P | 1 |
72137 | 1992 | 8-Hour Ozone (2015) | W | 1 |
72137 | 1992 | 'Nitrogen Dioxide (1971)' | 1 | |
72137 | 1993 | Sulfur Dioxide (1971) | ||
72137 | 1993 | PM-2.5 (1997) | ||
72137 | 1993 | 8-Hour Ozone (2015) | W | |
72137 | 1993 | 'Nitrogen Dioxide (1971)' |