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

ENH: Easy overview of content of dataframe #228

Open
thomasfrederikhoeck opened this issue Jun 20, 2019 · 0 comments
Open

ENH: Easy overview of content of dataframe #228

thomasfrederikhoeck opened this issue Jun 20, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@thomasfrederikhoeck
Copy link
Contributor

Before building any models and making any visualsations it is useful to inspect the data set first.
A function that gives a quick overview of the content could be the following. It is build for Jupyter Notebooks:

import pandas as pd
from IPython.display import display


def display_all(df):
    df_disp = pd.DataFrame(index=df.columns, columns=['type', 'count', 'unique', 'NaN',
                                                      'mean', 'median', 'std', 'min', 'max',
                                                      'values'])
    i = 0
    for col in df.columns:
        type_i = str(df[col].dtype)
        NaN_i = np.sum((pd.isnull(df[col])))
        count_i = len(df[col])-NaN_i
        unique_i = len(df[col].unique())
        col_unique = df[col].unique()
        if len(col_unique) > 1:
            val_i = str(col_unique[0]) + ', ' + str(col_unique[-1])
        else:
            val_i = str(col_unique[0])
        if type_i == 'object':
            mean_i = np.NaN
            median_i = np.NaN
            std_i = np.NaN
            min_i = np.NaN
            max_i = np.NaN
        else:
            mean_i = np.nanmean(df[col])
            median_i = np.nanmedian(df[col])
            std_i = np.nanstd(df[col])
            min_i = np.nanmin(df[col])
            max_i = np.nanmax(df[col])
        df_disp.iloc[i, :] = [type_i, count_i, unique_i, NaN_i, mean_i, median_i, std_i, min_i,
                              max_i, val_i]
        i += 1
    with pd.option_context('display.max_rows', None, 'display.max_columns', 10):
        display(df_disp)
@thomasfrederikhoeck thomasfrederikhoeck added the enhancement New feature or request label Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant