Skip to main content
`Ctrl`+`K`

# pandas.DataFrame.truediv

DataFrame.truediv(other, axis='columns', level=None, fill_value=None)

  Get Floating division of dataframe and other, element-wise (binary operator truediv).

  Equivalent to `dataframe / other`, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rtruediv.

  Among flexible wrappers (add, sub, mul, div, floordiv, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

  Parameters:
    other scalar, sequence, Series, dict or DataFrame

      Any single or multiple element data structure, or list-like object.

    axis{0 or ‘index’, 1 or ‘columns’}

      Whether to compare by the index (0 or ‘index’) or columns. (1 or ‘columns’). For Series input, axis to match Series index on.

    level int or label

      Broadcast across a level, matching Index values on the passed MultiIndex level.

    fill_value scalar or None, default None

      Fill NA values, whether present in the original data or introduced by alignment, with this value before computation. Positions where both inputs are NA are left unfilled and behave as NA does for the operation.

  Returns:
    DataFrame

      Result of the arithmetic operation.

  See also

  `DataFrame.add`

    Add DataFrames.

  `DataFrame.sub`

    Subtract DataFrames.

  `DataFrame.mul`

    Multiply DataFrames.

  `DataFrame.div`

    Divide DataFrames (float division).

  `DataFrame.truediv`

    Divide DataFrames (float division).

  `DataFrame.floordiv`

    Divide DataFrames (integer division).

  `DataFrame.mod`

    Calculate modulo (remainder after division).

  `DataFrame.pow`

    Calculate exponential power.

  Notes

  Mismatched indices will be unioned together.

  Examples

      >>> df = pd.DataFrame({'angles': [0, 3, 4],
      ...                    'degrees': [360, 180, 360]},
      ...                   index=['circle', 'triangle', 'rectangle'])
      >>> df
                 angles  degrees
      circle          0      360
      triangle        3      180
      rectangle       4      360

  Divide by a scalar.

      >>> df / 2
                 angles  degrees
      circle        0.0    180.0
      triangle      1.5     90.0
      rectangle     2.0    180.0

      >>> df.truediv(2)
                 angles  degrees
      circle        0.0    180.0
      triangle      1.5     90.0
      rectangle     2.0    180.0

  Divide by a list and Series.

      >>> df / [1, 2]
                 angles  degrees
      circle        0.0    180.0
      triangle      3.0     90.0
      rectangle     4.0    180.0

      >>> df.truediv([1, 2], axis='columns')
                 angles  degrees
      circle        0.0    180.0
      triangle      3.0     90.0
      rectangle     4.0    180.0

      >>> df.truediv(pd.Series([1, 2, 3], index=['circle', 'triangle', 'rectangle']),
      ...            axis='index')
                   angles  degrees
      circle     0.000000    360.0
      triangle   1.500000     90.0
      rectangle  1.333333    120.0

  Divide by a dictionary by axis.

      >>> df.truediv({'angles': 2, 'degrees': 3})
                 angles  degrees
      circle        0.0    120.0
      triangle      1.5     60.0
      rectangle     2.0    120.0

      >>> df.truediv({'circle': 1, 'triangle': 2, 'rectangle': 3}, axis='index')
                   angles  degrees
      circle     0.000000    360.0
      triangle   1.500000     90.0
      rectangle  1.333333    120.0