Skip to main content
`Ctrl`+`K`

# pandas.DataFrame.set_flags

DataFrame.set_flags(*, copy=<no_default>, allows_duplicate_labels=None)

  Return a new object with updated flags.

  This method creates a shallow copy of the original object, preserving its underlying data while modifying its global flags. In particular, it allows you to update properties such as whether duplicate labels are permitted. This behavior is especially useful in method chains, where one wishes to adjust DataFrame or Series characteristics without altering the original object.

  Parameters:
    copy bool, default False

      This keyword is now ignored; changing its value will have no impact on the method.

      Deprecated since version 3.0.0: This keyword is ignored and will be removed in pandas 4.0. Since pandas 3.0, this method always returns a new object using a lazy copy mechanism that defers copies until necessary (Copy-on-Write). See the user guide on Copy-on-Write for more details.

    allows_duplicate_labels bool, optional

      Whether the returned object allows duplicate labels.

  Returns:
    Series or DataFrame

      The same type as the caller.

  See also

  `DataFrame.attrs`

    Global metadata applying to this dataset.

  `DataFrame.flags`

    Global flags applying to this object.

  Notes

  This method returns a new object that’s a view on the same data as the input. Mutating the input or the output values will be reflected in the other.

  This method is intended to be used in method chains.

  “Flags” differ from “metadata”. Flags reflect properties of the pandas object (the Series or DataFrame). Metadata refer to properties of the dataset, and should be stored in `DataFrame.attrs`.

  Examples

      >>> df = pd.DataFrame({"A": [1, 2]})
      >>> df.flags.allows_duplicate_labels
      True
      >>> df2 = df.set_flags(allows_duplicate_labels=False)
      >>> df2.flags.allows_duplicate_labels
      False