Skip to main content

A tool for the Boston Globe for data cleaning

Project description

globestylizer

About state_abbr()

globestylizer is a Python library for use in the Boston Globe. It contains a function called state_abbr and has one dependency: pandas.

The intended use case for this library is for cleaning a pandas Dataframe that contains state abbreviations that are not adherent to Globe style, and returning a copy of the Dataframe that is in Globe style.

Installation

In your virtual environment, for example pipenv, pipenv install globestylizer. Remember that this is dependent on pandas as well.

Usage

Import globestylizer in your py file or Jupyter notebook: import globestylizer

You can call the state_abbr function on any pandas Dataframe and it will parse the entire Dataframe for state abbreviations or full state names. It is case-insensitive so it can handle any variety of capitalizations. Here's example data:

State1 State2 Value
Alaska Alaska 15
AK AK 654
AL AL 45.32
Alabama Alabama 789
Tennessee Tennessee 15
Tenn. Tenn. 3
TN TN 31.2
WYOMING WYOMING 789
wyoming wyoming 455
WYoming WYoming 11
WY WY 2

Assuming you have a pandas Dataframe defined as df, you can call it as so:

abbreviated_df = globestylizer.state_abbr(df)

And abbreviated_df will return:

State1 State2 Value
Alaska Alaska 15.0
Alaska Alaska 654.0
Ala. Ala. 45.32
Ala. Ala. 789.0
Tenn. Tenn. 15.0
Tenn. Tenn. 3.0
Tenn. Tenn. 31.2
Wyo. Wyo. 789.0
Wyo. Wyo. 455.0
Wyo. Wyo. 11.0
Wyo. Wyo. 2.0

You also have the option of parsing only selected columns. If you have state names as part of strings in other columns that you don't want abbreviated, pass in the columns that you do want abbreviated as a second argument. Assuming you have data as such, and only want to clean the column 'State2':

State1 State2 Value
Alaska Alaska 15
AK AK 654
AL AL 45.32
Alabama Alabama 789
Tennessee Tennessee 15
Tenn. Tenn. 3
TN TN 31.2
WYOMING WYOMING 789
wyoming wyoming 455
WYoming WYoming 11
WY WY 2

Pass in the column name as the second argument.

partially_abbreviated_df = globestylizer.state_abbr(df, columns=['State2'])

And partially_abbreviated_df will return:

State1 State2 Value
Alaska Alaska 15.0
AK Alaska 654.0
AL Ala. 45.32
Alabama Ala. 789.0
Tennessee Tenn. 15.0
Tenn. Tenn. 3.0
TN Tenn. 31.2
WYOMING Wyo. 789.0
wyoming Wyo. 455.0
WYoming Wyo. 11.0
WY Wyo. 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

globestylizer_kirkan95-0.1.7.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

globestylizer_kirkan95-0.1.7-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file globestylizer_kirkan95-0.1.7.tar.gz.

File metadata

  • Download URL: globestylizer_kirkan95-0.1.7.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for globestylizer_kirkan95-0.1.7.tar.gz
Algorithm Hash digest
SHA256 769085c784fdd502f276bb0ecf59f7f0c2af0502bf7ba39f880fde31dc115906
MD5 2d4c6762b2c9d80b388f0dd6eaadce39
BLAKE2b-256 60926364f8733d9309bdc61b8dc7a3c1b81c234ca1b384d8f48dfa446f4202dc

See more details on using hashes here.

File details

Details for the file globestylizer_kirkan95-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for globestylizer_kirkan95-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a4ec7e86552a624cd0561f7972146bdaed2c18778061d88d7878a94de0ab0e21
MD5 6663c39e2b244417f8f6cc65910885b6
BLAKE2b-256 571e6e79c9c605de7704f89649b30d105bf5f0e261af8795723f80c790afe37c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page