cnames generates a namedtuple for pandas dataframe columns. When added to the pandas DataFrame class through monkey patching column names can be obtained through tab completion in interactive mode.
This module uses namedtuples which were introduced in Python 2.6. Code was developed and tested on Python 3, Pandas 0.18.1 and IPython 5.3.0.
Python >= 2.6
Pandas >= 0.18.1
Use pip to install via wheel. If you have downloaded the module locally then change to that directory and use pip
pip install cnames-0.1-py2.py3-none-any.whl
You can also install via URL
pip install https://github.com/ebenp/cnames/releases/download/0.1/cnames-0.1-py2.py3-none-any.whl
A test dataframe under the main() statement in cnames.py is available for use.
After import assign cnames to the DataFrame class.
import pandas as pd
from cnames import cnames
# monkey-patch the DataFrame class
pd.DataFrame.cnames = cnames
To use cnames call the function on the desired DataFrame in interactive mode, in IPython or a debugging environment
# tab completetion will populate with
column names along with DataFrame attributes and methods
df.cnames().<tab completion>
In some cases, Jupyter Notebook and default IPython, IPCompleter.greedy needs to be set for cnames to correctly populate.
%config IPCompleter.greedy = True
However, be warned that enabling this option can be unsafe, because the code is actually evaluated upon hitting TAB. This is why the feature is disabled by default. Also, enabling this seems to prevent filepath completion inside of quotes.
Please feel free to submit issues or pull requests.
For the versions available, see the tags on this repository.
- Eben Pendleton - Initial work - ebenp
Modified from a stackoverflow answer. Answer was given by user Maturin. Thanks!
This project is licensed under the MIT License - see the LICENSE.md file for details