Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upt raw_fullacs to raw_acs, raw_acs to raw_spm_acs #57

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Kklu78
Copy link
Collaborator

@Kklu78 Kklu78 commented Nov 2, 2021

No description provided.

Copy link
Contributor

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the black code formatter with fix the linting error. You can integrate that to VSCode with these instructions, and you'll also need to adjust the line length to 79.

url = f"https://www2.census.gov/programs-surveys/acs/data/pums/{year}/1-Year/csv_pus.zip"
request = requests.get(url)
file = ZipFile(BytesIO(request.content))
file.extractall(f'{year}_pus')
Copy link
Contributor

@MaxGhenis MaxGhenis Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikhilwoodruff feel free to suggest otherwise given these are large files (larger than others), but to be consistent with other generate functions I think we'll want to avoid writing the source files to disk, and instead load from the zip file directly. This might make most sense as a function, something like this (not sure if it'll work):

def concat_zipped_csvs(url: str, prefix: str) -> pd.DataFrame:
    # Creates a DataFrame with the two csvs inside a zip file from a URL.
    zf = ZipFile(BytesIO(requests.get(url)))
    a = pd.read_csv(zf.open(prefix + "a.csv"))
    b = pd.read_csv(zf.open(prefix + "b.csv"))
    res = pd.concat([a, b]).fillna(0)
    res.columns = res.columns.str.lower()
    return res

Then called as:

person_df = concat_zipped_csvs(
    f"https://www2.census.gov/programs-surveys/acs/data/pums/{year}/1-Year/csv_pus.zip",
    "psam_pus"
)

And similarly for household.

Copy link
Contributor

@nikhilwoodruff nikhilwoodruff Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine as a general approach for large files - though I did envisage something similar to openfisca-uk-data's download() function (either from gcp or GitHub) being useful here


def create_household_table(person: pd.DataFrame) -> pd.DataFrame:
return person[["SERIALNO", "ST", "PUMA"]].groupby(person.SERIALNO).first()
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a newline

Copy link
Contributor

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple other small things.

Also for posterity, note that raw_spm_acs.py is essentially just renamed from raw_acs.py, the diff just isn't showing it as such unfortunately, maybe because there's now a new raw_acs.py which is the full ACS.

### ACS
- OpenFisca-US-compatible
- Contains OpenFisca-US-compatible input arrays.
- Contains OpenFisca-US-compatible input arrays from the spm research file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Contains OpenFisca-US-compatible input arrays from the spm research file.
- Contains OpenFisca-US-compatible input arrays from the SPM research file.

@@ -3,4 +3,4 @@

REPO = Path(__file__).parent

DATASETS = (RawCPS, CPS, RawACS, ACS)
DATASETS = (RawCPS, CPS, RawACS, ACS, RawSPMACS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DATASETS = (RawCPS, CPS, RawACS, ACS, RawSPMACS)
DATASETS = (RawCPS, CPS, RawACS, RawSPMACS, ACS)

Copy link
Contributor

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add MAR (marital status) from the raw ACS person file to demonstrate it beyond the SPM file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename existing RawACS to RawSPMACS
3 participants