df_describe_numeric Subroutine

public subroutine df_describe_numeric(df, unit)

Print summary statistics for all numeric columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
integer, intent(in), optional :: unit

Source Code

    subroutine df_describe_numeric(df, unit)
        type(data_frame), intent(in) :: df
        integer, intent(in), optional :: unit

        integer :: out_unit, i, dtype
        character(len=25) :: col_name
        type(column) :: data_col

        if (present(unit)) then
            out_unit = unit
        else
            out_unit = 6  ! stdout
        end if

        write (out_unit, '(a)') ""
        write (out_unit, '(a)') repeat('=', 80)
        write (out_unit, '(a)') "Numeric Column Statistics"
        write (out_unit, '(a)') repeat('=', 80)
        write (out_unit, '(a)') ""

        do i = 1, df % ncols()
            data_col = df % get_data_col(i)
            dtype = data_col % get_type()

            ! Only process real and integer columns
            if (dtype == REAL_NUM .or. dtype == INTEGER_NUM) then
                if (df % get_with_headers()) then
                    col_name = trim(df % header(i))
                else
                    write (col_name, '(a,i0)') "Column ", i
                end if

                write (out_unit, '(a)') trim(col_name)
                write (out_unit, '(a)') repeat('-', len(trim(col_name)))

                if (dtype == REAL_NUM) then
                    write (out_unit, '(a,f12.4)') "  Count:       ", real(df % nrows(), rk)
                    write (out_unit, '(a,f12.4)') "  Mean:        ", df_mean_real(df, i)
                    write (out_unit, '(a,f12.4)') "  Std Dev:     ", df_std_real(df, i)
                    write (out_unit, '(a,f12.4)') "  Min:         ", df_min_real(df, i)
                    write (out_unit, '(a,f12.4)') "  25%:         ", df_percentile_real(df, i, 25.0_rk)
                    write (out_unit, '(a,f12.4)') "  Median (50%):", df_median_real(df, i)
                    write (out_unit, '(a,f12.4)') "  75%:         ", df_percentile_real(df, i, 75.0_rk)
                    write (out_unit, '(a,f12.4)') "  Max:         ", df_max_real(df, i)
                else ! INTEGER_NUM
                    write (out_unit, '(a,i12)') "  Count:       ", df % nrows()
                    write (out_unit, '(a,f12.2)') "  Mean:        ", df_mean_integer(df, i)
                    write (out_unit, '(a,f12.2)') "  Std Dev:     ", df_std_integer(df, i)
                    write (out_unit, '(a,i12)') "  Min:         ", df_min_integer(df, i)
                    write (out_unit, '(a,f12.2)') "  25%:         ", df_percentile_integer(df, i, 25.0_rk)
                    write (out_unit, '(a,f12.2)') "  Median (50%):", df_median_integer(df, i)
                    write (out_unit, '(a,f12.2)') "  75%:         ", df_percentile_integer(df, i, 75.0_rk)
                    write (out_unit, '(a,i12)') "  Max:         ", df_max_integer(df, i)
                end if

                write (out_unit, '(a)') ""
            end if
        end do

        write (out_unit, '(a)') repeat('=', 80)
    end subroutine df_describe_numeric