From ba0c4d7e2101a09bb97d7be08c698119c5d08c27 Mon Sep 17 00:00:00 2001 From: MohakGangwani <60480420+MohakGangwani@users.noreply.github.com> Date: Mon, 1 Jun 2020 19:20:08 +0530 Subject: [PATCH] Update : In DataFrame Class, Columns should not contain duplicate values. Also updated the Docstring. --- pandas/core/frame.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index dfc938918f03a..ce47314ad4328 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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 @@ -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