Giter VIP home page Giter VIP logo

fix_df_cols's Introduction

fix_df_cols

I dislike columns with names that slow my work. This package will convert all columns names to snake_case, using the following rules:

  1. Everything (all columns) are converted to lowercase.
  2. All spaces are replaced with underscores.
  3. Everything that isn't a letter, digit, or underscore (in a column name) is removed.

Installation

git clone https://github.com/jonnagel/fix_df_cols.git

TODO

Usage

Create a pd.DataFrame as normal, then run clean() method to fix the column names. This adds a clean() method to all pd.DataFrames, calling this method fixes the columns in place.

from fix_df_cols.src.fixdfcols import CleanDF
bad_df = pd.DataFrame(columns=['abc -@#ab%@', '12 3', 'a**bcCCC'])
# bad_df.columns
#   Index(['abc -@#ab%@', '12 3', 'a**bc'], dtype='object')
bad_df.clean()
# bad_df.columns
#   Index(['abc_ab', '12_3', 'abc'], dtype='object')

Standalone example

# a python list or pd.Index works as a manual fix 
from src.fixdfcols import FixCols
clean_cols = FixCols(['abc -@#ab%@', '12 3', 'a**bcEB']).columns_clean
# clean_cols
# ['abc_ab', '12_3', 'abceb']

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

fix_df_cols's People

Contributors

jonnagel avatar

Watchers

 avatar

fix_df_cols's Issues

columns starting with a space

as is

df.columns
#  [' AAA', 'AAB']
df.clean()
df.columns
#  ['_aaa', 'aab']

deal with column names starting with unwanted characters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.