0

I try to create new columns in my DataFrame 'self.__transformed' by copying some columns of 'self.__original'

self.__transformed[new_col] = self.__original[col]

However I get this error:

ValueError: Wrong number of items passed 2, placement implies 1

new_col and col are lists of column names

This : print(len(col), len(new_col)) returns: 45 45

By doing display(self.__original[col]) I see my 45 columns without anything special.

I don't understand what can be the possible reason of this error as I have the same numbers of columns. In particular I don't understand why passed 2 because I have 45 columns, not 2 !?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sitrus
  • 31
  • 1
  • Does this answer your question? [ValueError: Wrong number of items passed - Meaning and suggestions?](https://stackoverflow.com/questions/43196907/valueerror-wrong-number-of-items-passed-meaning-and-suggestions) – Rob Streeting Jun 07 '21 at 14:50
  • I learned there that a possible reason for this error is that I don't have any rows in my DataFrames but I have 4321 rows in both. Obviously self.__transformed[new_col] is empty because I'm creating these columns, is it a problem ? – Sitrus Jun 07 '21 at 15:12
  • I solved my problem using `c = [i for i in self.__transformed.columns if not(i in col)] self.__transformed = self.pd.concat([self.__transformed[c], self.__original[col]], axis=1)` – Sitrus Jun 07 '21 at 16:34

0 Answers0