Module pandas_profiling.controller.console

This file add the console interface to the package.

Expand source code
"""This file add the console interface to the package."""
from pathlib import Path
import argparse
from typing import Union

from pandas_profiling.__init__ import __version__, ProfileReport
from pandas_profiling.config import config
from pandas_profiling.utils.dataframe import read_pandas


def parse_args(args: Union[list, None] = None) -> argparse.Namespace:
    """Parse the command line arguments for the `pandas_profiling` binary.

    Args:
      args: List of input arguments. (Default value=None).

    Returns:
      Namespace with parsed arguments.

    """
    parser = argparse.ArgumentParser(
        description="Profile the variables in a CSV file and generate a HTML report."
    )

    # Version
    parser.add_argument(
        "--version",
        action="version",
        version="%(prog)s {version}".format(version=__version__),
    )

    # Console specific
    parser.add_argument(
        "-s",
        "--silent",
        help="Only generate but do not open report",
        action="store_true",
    )

    parser.add_argument(
        "-m",
        "--minimal",
        help="Minimal configuration for big data sets",
        action="store_true",
    )

    # Config
    parser.add_argument(
        "--pool_size", type=int, default=0, help="Number of CPU cores to use"
    )
    parser.add_argument(
        "--title",
        type=str,
        default="Pandas Profiling Report",
        help="Title for the report",
    )

    parser.add_argument(
        "--config_file",
        type=str,
        default=None,
        help="Specify a yaml config file. Have a look at the 'config_default.yaml' as a starting point.",
    )

    parser.add_argument(
        "input_file",
        type=str,
        help="CSV file (or other file type supported by pandas) to profile",
    )
    parser.add_argument("output_file", type=str, help="Output report file")

    return parser.parse_args(args)


def main(args=None) -> None:
    """ Run the `pandas_profiling` package.

    Args:
      args: Arguments for the programme (Default value=None).
    """

    # Parse the arguments
    args = parse_args(args)
    config.set_args(args, dots=True)

    # read the DataFrame
    df = read_pandas(Path(args.input_file))

    # Generate the profiling report
    p = ProfileReport(df, minimal=args.minimal, config_file=args.config_file)
    p.to_file(output_file=Path(args.output_file), silent=args.silent)

Functions

def main(args=None)

Run the pandas_profiling package.

Args

args
Arguments for the programme (Default value=None).
Expand source code
def main(args=None) -> None:
    """ Run the `pandas_profiling` package.

    Args:
      args: Arguments for the programme (Default value=None).
    """

    # Parse the arguments
    args = parse_args(args)
    config.set_args(args, dots=True)

    # read the DataFrame
    df = read_pandas(Path(args.input_file))

    # Generate the profiling report
    p = ProfileReport(df, minimal=args.minimal, config_file=args.config_file)
    p.to_file(output_file=Path(args.output_file), silent=args.silent)
def parse_args(args=None)

Parse the command line arguments for the pandas_profiling binary.

Args

args
List of input arguments. (Default value=None).

Returns

Namespace with parsed arguments.

Expand source code
def parse_args(args: Union[list, None] = None) -> argparse.Namespace:
    """Parse the command line arguments for the `pandas_profiling` binary.

    Args:
      args: List of input arguments. (Default value=None).

    Returns:
      Namespace with parsed arguments.

    """
    parser = argparse.ArgumentParser(
        description="Profile the variables in a CSV file and generate a HTML report."
    )

    # Version
    parser.add_argument(
        "--version",
        action="version",
        version="%(prog)s {version}".format(version=__version__),
    )

    # Console specific
    parser.add_argument(
        "-s",
        "--silent",
        help="Only generate but do not open report",
        action="store_true",
    )

    parser.add_argument(
        "-m",
        "--minimal",
        help="Minimal configuration for big data sets",
        action="store_true",
    )

    # Config
    parser.add_argument(
        "--pool_size", type=int, default=0, help="Number of CPU cores to use"
    )
    parser.add_argument(
        "--title",
        type=str,
        default="Pandas Profiling Report",
        help="Title for the report",
    )

    parser.add_argument(
        "--config_file",
        type=str,
        default=None,
        help="Specify a yaml config file. Have a look at the 'config_default.yaml' as a starting point.",
    )

    parser.add_argument(
        "input_file",
        type=str,
        help="CSV file (or other file type supported by pandas) to profile",
    )
    parser.add_argument("output_file", type=str, help="Output report file")

    return parser.parse_args(args)