diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0185ca8241617..2d07e67654163 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2866,7 +2866,7 @@ def to_parquet( Returns ------- bytes if no path argument is provided else None - + See Also -------- read_parquet : Read a parquet file. @@ -8984,6 +8984,10 @@ def groupby( if level is None and by is None: raise TypeError("You have to supply one of 'by' and 'level'") + + if not as_index and isinstance(by, Series) and by.name in self.columns: + raise ValueError(f"cannot insert {by.name}, already exists") + return DataFrameGroupBy( obj=self,