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

Script for data reading/wrangling #25

Conversation

dhuppenkothen
Copy link
Contributor

@dhuppenkothen dhuppenkothen commented Feb 4, 2017

I took the code from the notebook that got merged today, along with this notebook and made a script that can be called from the command line. Of course, the functions can all also be important and called from within python.

It allows the user to decide which data to download (including all), and also includes a helper function to avoid duplicating a lot of code. Examples:

  • Get help:
    python read_data.py -h

  • Download all data into a specified directory:
    python read_data.py -a -d "/path/to/data/directory/"

  • Download Part D data only into the default directory "../data/":
    python read_data.py --download-partd

  • Don't download data, but make a file that associates drug names with classes and IDs:
    python read_data.py --make-drug-table

I also made a small change to the notebook referenced above, to remove the dependency on openpyxl, which is unnecessary given that we're importing pandas anyway.

Comments/suggestions welcome. :)

mattgawarecki and others added 23 commits December 29, 2016 09:02
- (External) Move all data files to data.world repository (https://data.world/data4democracy/drug-spending)
- Remove data/ directory
- Correct notebook code to work with data.world as a source
@jenniferthompson
Copy link
Contributor

Added @mattgawarecki as a reviewer because Python, but this sounds fantastic! Thanks, @dhuppenkothen!

dhuppenkothen and others added 2 commits February 4, 2017 13:57
@mattgawarecki mattgawarecki merged commit df5ae74 into Data4Democracy:master Feb 4, 2017
@mattgawarecki
Copy link
Contributor

This PR was getting to be quite large -- I see some small places where we could improve, but I'm not going to let "perfect" get in the way of "great" here. Merged with great pleasure! 👍

mattgawarecki pushed a commit that referenced this pull request Feb 15, 2017
* Data Wrangling for Drug Use Visualizations (#24)

* Pulling drug use classes out of the CMS PUF files for categorizing the Plan D data

* Fixed directory creating, refactored df, shortened loop

* Script for data reading/wrangling (#25)

* Fix gitignore to ignore XLSX/ZIP and move CMS data to its own dir

* Add drug names back into annual spending data, for ease of use

* Forgot to add notebook in last commit

* Fix exploration notebook after earlier changes

* Add .DS_Store files to .gitignore

* Remove Medicare drug spending dataset (migrated to data.world)

* Remove data in favor of using data.world

- (External) Move all data files to data.world repository (https://data.world/data4democracy/drug-spending)
- Remove data/ directory
- Correct notebook code to work with data.world as a source

* Wrote a helper function that gets data from a URL, wrote function that downloads Part D data based on notebook

* Added docstring to function

* Added more functions that load data wrangle it

* Added argument parser and squashed some bugs

* Removed dependence on openpyxl, since Pandas does the trick

* Notebook runs

* Minor change to command line arg and addition to help string

* Move comments into Markdown cells and add CSV output

* Added functionality to decide between input/output data formats; supports cvs and feather at the moment

* Small bug fix to remove hard-coded directory paths (#28)

* Markdown version of goals statement - first draft.

* add USP drug classification tidying and data dictionary

* Added anchor for citations and superscripted refs

* Cleaning drug manufacturer data

source:
https://www.cms.gov/Medicare/Medicare-Fee-for-Service-Part-B-Drugs/McrPartBDrugAvgSalesPrice/2016ASPFiles.html

* move USP Drug Classification to

* clarify usp drug classification data dict info

* small changes

* update links

* small changes

* download from data.world, clean up functions, add comments

* added direct link to the datasets of interest

* Restructuring of repo (#36)

* Reorganization FTW

* Reorganization FTW, part 2

* Add .gitignore

* Add READMEs to each subdirectory. Rename data dictionary template (now TEMPLATE) and remove suffix from manufacturer_datadict.md.

* Add link to data.world Python client

* Update main README to reflect new file structure

* Fix link to datadictionaries

* Really fix it this time

* Fix the other datadictionaries links to overview and template

* More streamlining and edits to README

* Add @skirmer to maintainers!

* Correct directory name for datadictionaries

* Add link to objectives doc

* Update datadictionaries/README.md to reflect updated repo structure

* update files to reflect repo structure changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants