- API reference
- DataFrame
- pandas.DataF...
pandas.DataFrame.set_flags#
- DataFrame.set_flags(*,copy=False,allows_duplicate_labels=None)[source]#
Return a new object with updated flags.
- Parameters:
- copybool, default False
Specify if a copy of the object should be made.
Note
Thecopy keyword will change behavior in pandas 3.0.Copy-on-Writewill be enabled by default, which means that all methods with acopy keyword will use a lazy copy mechanism to defer the copy andignore thecopy keyword. Thecopy keyword will be removed in afuture version of pandas.
You can already get the future behavior and improvements throughenabling copy on write
pd.options.mode.copy_on_write=True
- allows_duplicate_labelsbool, 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 dataas the input. Mutating the input or the output values will be reflectedin the other.
This method is intended to be used in method chains.
“Flags” differ from “metadata”. Flags reflect properties of thepandas object (the Series or DataFrame). Metadata refer to propertiesof the dataset, and should be stored in
DataFrame.attrs
.Examples
>>>df=pd.DataFrame({"A":[1,2]})>>>df.flags.allows_duplicate_labelsTrue>>>df2=df.set_flags(allows_duplicate_labels=False)>>>df2.flags.allows_duplicate_labelsFalse