Skip to content

Update : In DataFrame Class, Columns should not contain duplicate val… #34512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ class DataFrame(NDFrame):
columns : Index or array-like
Column labels to use for resulting frame. Will default to
RangeIndex (0, 1, 2, ..., n) if no column labels are provided.
Columns Labels should not contain duplicate values, if column
labels are provided.
dtype : dtype, default None
Data type to force. Only a single dtype is allowed. If None, infer.
copy : bool, default False
Expand Down Expand Up @@ -442,6 +444,11 @@ def __init__(
data = {}
if dtype is not None:
dtype = self._validate_dtype(dtype)

#We need columns to have unique labels.
if columns != None:
if len(columns) != len(set(columns)):
raise Exception("Columns should not contain duplicate values.")

if isinstance(data, DataFrame):
data = data._mgr
Expand Down