Python pandas.io.formats.printing.justify() Examples

The following are 30 code examples of pandas.io.formats.printing.justify(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.io.formats.printing , or try the search function .
Example #1
Source File: format.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def _format_strings(self):
        values = self.values
        if isinstance(values, (ABCIndexClass, ABCSeries)):
            values = values._values

        formatter = values._formatter(boxed=True)

        if is_categorical_dtype(values.dtype):
            # Categorical is special for now, so that we can preserve tzinfo
            array = values.get_values()
        else:
            array = np.asarray(values)

        fmt_values = format_array(array,
                                  formatter,
                                  float_format=self.float_format,
                                  na_rep=self.na_rep, digits=self.digits,
                                  space=self.space, justify=self.justify,
                                  leading_space=self.leading_space)
        return fmt_values 
Example #2
Source File: format.py    From recruit with Apache License 2.0 6 votes vote down vote up
def _format_strings(self):
        values = self.values
        if isinstance(values, (ABCIndexClass, ABCSeries)):
            values = values._values

        formatter = values._formatter(boxed=True)

        if is_categorical_dtype(values.dtype):
            # Categorical is special for now, so that we can preserve tzinfo
            array = values.get_values()
        else:
            array = np.asarray(values)

        fmt_values = format_array(array,
                                  formatter,
                                  float_format=self.float_format,
                                  na_rep=self.na_rep, digits=self.digits,
                                  space=self.space, justify=self.justify,
                                  leading_space=self.leading_space)
        return fmt_values 
Example #3
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _format_strings(self):
        fmt_values = format_array(self.values.get_values(), self.formatter,
                                  float_format=self.float_format,
                                  na_rep=self.na_rep, digits=self.digits,
                                  space=self.space, justify=self.justify)
        return fmt_values 
Example #4
Source File: format.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def __init__(self, values, digits=7, formatter=None, na_rep='NaN',
                 space=12, float_format=None, justify='right', decimal='.',
                 quoting=None, fixed_width=True, leading_space=None):
        self.values = values
        self.digits = digits
        self.na_rep = na_rep
        self.space = space
        self.formatter = formatter
        self.float_format = float_format
        self.justify = justify
        self.decimal = decimal
        self.quoting = quoting
        self.fixed_width = fixed_width
        self.leading_space = leading_space 
Example #5
Source File: format.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def get_result(self):
        fmt_values = self._format_strings()
        return _make_fixed_width(fmt_values, self.justify) 
Example #6
Source File: format.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def _make_fixed_width(strings, justify='right', minimum=None, adj=None):

    if len(strings) == 0 or justify == 'all':
        return strings

    if adj is None:
        adj = _get_adjustment()

    max_len = max(adj.len(x) for x in strings)

    if minimum is not None:
        max_len = max(minimum, max_len)

    conf_max = get_option("display.max_colwidth")
    if conf_max is not None and max_len > conf_max:
        max_len = conf_max

    def just(x):
        if conf_max is not None:
            if (conf_max > 3) & (adj.len(x) > max_len):
                x = x[:max_len - 3] + '...'
        return x

    strings = [just(x) for x in strings]
    result = adj.justify(strings, max_len, mode=justify)
    return result 
Example #7
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def to_string(self):
        series = self.tr_series
        footer = self._get_footer()

        if len(series) == 0:
            return 'Series([], ' + footer + ')'

        fmt_index, have_header = self._get_formatted_index()
        fmt_values = self._get_formatted_values()

        if self.truncate_v:
            n_header_rows = 0
            row_num = self.tr_row_num
            width = self.adj.len(fmt_values[row_num - 1])
            if width > 3:
                dot_str = '...'
            else:
                dot_str = '..'
            # Series uses mode=center because it has single value columns
            # DataFrame uses mode=left
            dot_str = self.adj.justify([dot_str], width, mode='center')[0]
            fmt_values.insert(row_num + n_header_rows, dot_str)
            fmt_index.insert(row_num + 1, '')

        if self.index:
            result = self.adj.adjoin(3, *[fmt_index[1:], fmt_values])
        else:
            result = self.adj.adjoin(3, fmt_values).replace('\n ',
                                                            '\n').strip()

        if self.header and have_header:
            result = fmt_index[0] + '\n' + result

        if footer:
            result += '\n' + footer

        return compat.text_type(u('').join(result)) 
Example #8
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        return justify(texts, max_len, mode=mode) 
Example #9
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def adjoin(self, space, *lists, **kwargs):
        return adjoin(space, *lists, strlen=self.len,
                      justfunc=self.justify, **kwargs) 
Example #10
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        # re-calculate padding space per str considering East Asian Width
        def _get_pad(t):
            return max_len - self.len(t) + len(t)

        if mode == 'left':
            return [x.ljust(_get_pad(x)) for x in texts]
        elif mode == 'center':
            return [x.center(_get_pad(x)) for x in texts]
        else:
            return [x.rjust(_get_pad(x)) for x in texts] 
Example #11
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def format_array(values, formatter, float_format=None, na_rep='NaN',
                 digits=None, space=None, justify='right', decimal='.'):

    if is_categorical_dtype(values):
        fmt_klass = CategoricalArrayFormatter
    elif is_interval_dtype(values):
        fmt_klass = IntervalArrayFormatter
    elif is_float_dtype(values.dtype):
        fmt_klass = FloatArrayFormatter
    elif is_period_arraylike(values):
        fmt_klass = PeriodArrayFormatter
    elif is_integer_dtype(values.dtype):
        fmt_klass = IntArrayFormatter
    elif is_datetimetz(values):
        fmt_klass = Datetime64TZFormatter
    elif is_datetime64_dtype(values.dtype):
        fmt_klass = Datetime64Formatter
    elif is_timedelta64_dtype(values.dtype):
        fmt_klass = Timedelta64Formatter
    else:
        fmt_klass = GenericArrayFormatter

    if space is None:
        space = get_option("display.column_space")

    if float_format is None:
        float_format = get_option("display.float_format")

    if digits is None:
        digits = get_option("display.precision")

    fmt_obj = fmt_klass(values, digits=digits, na_rep=na_rep,
                        float_format=float_format, formatter=formatter,
                        space=space, justify=justify, decimal=decimal)

    return fmt_obj.get_result() 
Example #12
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, values, digits=7, formatter=None, na_rep='NaN',
                 space=12, float_format=None, justify='right', decimal='.',
                 quoting=None, fixed_width=True):
        self.values = values
        self.digits = digits
        self.na_rep = na_rep
        self.space = space
        self.formatter = formatter
        self.float_format = float_format
        self.justify = justify
        self.decimal = decimal
        self.quoting = quoting
        self.fixed_width = fixed_width 
Example #13
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_result(self):
        fmt_values = self._format_strings()
        return _make_fixed_width(fmt_values, self.justify) 
Example #14
Source File: format.py    From recruit with Apache License 2.0 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        return justify(texts, max_len, mode=mode) 
Example #15
Source File: format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _make_fixed_width(strings, justify='right', minimum=None, adj=None):

    if len(strings) == 0 or justify == 'all':
        return strings

    if adj is None:
        adj = _get_adjustment()

    max_len = np.max([adj.len(x) for x in strings])

    if minimum is not None:
        max_len = max(minimum, max_len)

    conf_max = get_option("display.max_colwidth")
    if conf_max is not None and max_len > conf_max:
        max_len = conf_max

    def just(x):
        if conf_max is not None:
            if (conf_max > 3) & (adj.len(x) > max_len):
                x = x[:max_len - 3] + '...'
        return x

    strings = [just(x) for x in strings]
    result = adj.justify(strings, max_len, mode=justify)
    return result 
Example #16
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def to_string(self):
        series = self.tr_series
        footer = self._get_footer()

        if len(series) == 0:
            return 'Series([], ' + footer + ')'

        fmt_index, have_header = self._get_formatted_index()
        fmt_values = self._get_formatted_values()

        if self.truncate_v:
            n_header_rows = 0
            row_num = self.tr_row_num
            width = self.adj.len(fmt_values[row_num - 1])
            if width > 3:
                dot_str = '...'
            else:
                dot_str = '..'
            # Series uses mode=center because it has single value columns
            # DataFrame uses mode=left
            dot_str = self.adj.justify([dot_str], width, mode='center')[0]
            fmt_values.insert(row_num + n_header_rows, dot_str)
            fmt_index.insert(row_num + 1, '')

        if self.index:
            result = self.adj.adjoin(3, *[fmt_index[1:], fmt_values])
        else:
            result = self.adj.adjoin(3, fmt_values).replace('\n ',
                                                            '\n').strip()

        if self.header and have_header:
            result = fmt_index[0] + '\n' + result

        if footer:
            result += '\n' + footer

        return compat.text_type(u('').join(result)) 
Example #17
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        return justify(texts, max_len, mode=mode) 
Example #18
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def adjoin(self, space, *lists, **kwargs):
        return adjoin(space, *lists, strlen=self.len,
                      justfunc=self.justify, **kwargs) 
Example #19
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        # re-calculate padding space per str considering East Asian Width
        def _get_pad(t):
            return max_len - self.len(t) + len(t)

        if mode == 'left':
            return [x.ljust(_get_pad(x)) for x in texts]
        elif mode == 'center':
            return [x.center(_get_pad(x)) for x in texts]
        else:
            return [x.rjust(_get_pad(x)) for x in texts] 
Example #20
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def format_array(values, formatter, float_format=None, na_rep='NaN',
                 digits=None, space=None, justify='right', decimal='.'):

    if is_categorical_dtype(values):
        fmt_klass = CategoricalArrayFormatter
    elif is_interval_dtype(values):
        fmt_klass = IntervalArrayFormatter
    elif is_float_dtype(values.dtype):
        fmt_klass = FloatArrayFormatter
    elif is_period_arraylike(values):
        fmt_klass = PeriodArrayFormatter
    elif is_integer_dtype(values.dtype):
        fmt_klass = IntArrayFormatter
    elif is_datetimetz(values):
        fmt_klass = Datetime64TZFormatter
    elif is_datetime64_dtype(values.dtype):
        fmt_klass = Datetime64Formatter
    elif is_timedelta64_dtype(values.dtype):
        fmt_klass = Timedelta64Formatter
    else:
        fmt_klass = GenericArrayFormatter

    if space is None:
        space = get_option("display.column_space")

    if float_format is None:
        float_format = get_option("display.float_format")

    if digits is None:
        digits = get_option("display.precision")

    fmt_obj = fmt_klass(values, digits=digits, na_rep=na_rep,
                        float_format=float_format, formatter=formatter,
                        space=space, justify=justify, decimal=decimal)

    return fmt_obj.get_result() 
Example #21
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, values, digits=7, formatter=None, na_rep='NaN',
                 space=12, float_format=None, justify='right', decimal='.',
                 quoting=None, fixed_width=True):
        self.values = values
        self.digits = digits
        self.na_rep = na_rep
        self.space = space
        self.formatter = formatter
        self.float_format = float_format
        self.justify = justify
        self.decimal = decimal
        self.quoting = quoting
        self.fixed_width = fixed_width 
Example #22
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def get_result(self):
        fmt_values = self._format_strings()
        return _make_fixed_width(fmt_values, self.justify) 
Example #23
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def _format_strings(self):
        fmt_values = format_array(self.values.get_values(), self.formatter,
                                  float_format=self.float_format,
                                  na_rep=self.na_rep, digits=self.digits,
                                  space=self.space, justify=self.justify)
        return fmt_values 
Example #24
Source File: format.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def _make_fixed_width(strings, justify='right', minimum=None, adj=None):

    if len(strings) == 0 or justify == 'all':
        return strings

    if adj is None:
        adj = _get_adjustment()

    max_len = np.max([adj.len(x) for x in strings])

    if minimum is not None:
        max_len = max(minimum, max_len)

    conf_max = get_option("display.max_colwidth")
    if conf_max is not None and max_len > conf_max:
        max_len = conf_max

    def just(x):
        if conf_max is not None:
            if (conf_max > 3) & (adj.len(x) > max_len):
                x = x[:max_len - 3] + '...'
        return x

    strings = [just(x) for x in strings]
    result = adj.justify(strings, max_len, mode=justify)
    return result 
Example #25
Source File: format.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        # re-calculate padding space per str considering East Asian Width
        def _get_pad(t):
            return max_len - self.len(t) + len(t)

        if mode == 'left':
            return [x.ljust(_get_pad(x)) for x in texts]
        elif mode == 'center':
            return [x.center(_get_pad(x)) for x in texts]
        else:
            return [x.rjust(_get_pad(x)) for x in texts] 
Example #26
Source File: format.py    From recruit with Apache License 2.0 5 votes vote down vote up
def to_string(self):
        series = self.tr_series
        footer = self._get_footer()

        if len(series) == 0:
            return 'Series([], ' + footer + ')'

        fmt_index, have_header = self._get_formatted_index()
        fmt_values = self._get_formatted_values()

        if self.truncate_v:
            n_header_rows = 0
            row_num = self.tr_row_num
            width = self.adj.len(fmt_values[row_num - 1])
            if width > 3:
                dot_str = '...'
            else:
                dot_str = '..'
            # Series uses mode=center because it has single value columns
            # DataFrame uses mode=left
            dot_str = self.adj.justify([dot_str], width, mode='center')[0]
            fmt_values.insert(row_num + n_header_rows, dot_str)
            fmt_index.insert(row_num + 1, '')

        if self.index:
            result = self.adj.adjoin(3, *[fmt_index[1:], fmt_values])
        else:
            result = self.adj.adjoin(3, fmt_values)

        if self.header and have_header:
            result = fmt_index[0] + '\n' + result

        if footer:
            result += '\n' + footer

        return compat.text_type(u('').join(result)) 
Example #27
Source File: format.py    From recruit with Apache License 2.0 5 votes vote down vote up
def adjoin(self, space, *lists, **kwargs):
        return adjoin(space, *lists, strlen=self.len,
                      justfunc=self.justify, **kwargs) 
Example #28
Source File: format.py    From recruit with Apache License 2.0 5 votes vote down vote up
def justify(self, texts, max_len, mode='right'):
        # re-calculate padding space per str considering East Asian Width
        def _get_pad(t):
            return max_len - self.len(t) + len(t)

        if mode == 'left':
            return [x.ljust(_get_pad(x)) for x in texts]
        elif mode == 'center':
            return [x.center(_get_pad(x)) for x in texts]
        else:
            return [x.rjust(_get_pad(x)) for x in texts] 
Example #29
Source File: format.py    From recruit with Apache License 2.0 5 votes vote down vote up
def __init__(self, values, digits=7, formatter=None, na_rep='NaN',
                 space=12, float_format=None, justify='right', decimal='.',
                 quoting=None, fixed_width=True, leading_space=None):
        self.values = values
        self.digits = digits
        self.na_rep = na_rep
        self.space = space
        self.formatter = formatter
        self.float_format = float_format
        self.justify = justify
        self.decimal = decimal
        self.quoting = quoting
        self.fixed_width = fixed_width
        self.leading_space = leading_space 
Example #30
Source File: format.py    From recruit with Apache License 2.0 5 votes vote down vote up
def get_result(self):
        fmt_values = self._format_strings()
        return _make_fixed_width(fmt_values, self.justify)