0

I have the below mentioned data frame as df.

           A         B         C         D         E
0     sarang  1.138380 -0.383898 -0.444186 -0.383898
1    -1.1499 -0.469425 -1.455522 -0.789694 -1.455522
2  -0.688895 -0.737444 -0.238886 -0.602263 -0.238886
3   -1.02036  0.400622 -0.020911 -1.366732 -0.020911
4    1.97958 -1.252052 -0.977561 -0.111656 -0.977561
5  0.0802027 -0.290397  1.672563  0.371790  1.672563

I am trying to concat the column C and D, into a new column 'E' using :

df['E']  = pd.concat([df['C'], df['D']])

The error it gives me is :

ValueError: cannot reindex from a duplicate axis

Also I if use the ignore_index command,

df['E']  = pd.concat([df['C'], df['D']], ignore_index = True)

Then I get the below output, which I'm unable to understand at all.

           A         B         C         D         E
0     sarang  1.138380 -0.383898 -0.444186 -0.383898
1    -1.1499 -0.469425 -1.455522 -0.789694 -1.455522
2  -0.688895 -0.737444 -0.238886 -0.602263 -0.238886
3   -1.02036  0.400622 -0.020911 -1.366732 -0.020911
4    1.97958 -1.252052 -0.977561 -0.111656 -0.977561
5  0.0802027 -0.290397  1.672563  0.371790  1.672563

What should I do otherwise to get rid of the error.

Sarang Manjrekar
  • 1,839
  • 5
  • 31
  • 61

0 Answers0