0

Apologies for the title, I couldn't find a better way to frame my question.

I have two columns df['c1'], df['c2']. I want to pass every value from both these columns into a function to get a result (for every row) and have this series of results as a new column df['c3'].

what I've tried:

df['c3'] = function(df['c1'], df['c2'])

Unfortunately I get TypeError: cannot convert the series to class 'float'

So how exactly do I iterate over every value of both the series (df['c1'], df['c2']) to produce my column df['c3'] ?

Aakash Dusane
  • 388
  • 4
  • 17
  • 1
    https://stackoverflow.com/questions/43619896/python-pandas-iterate-over-rows-and-access-column-names/43620031#43620031 – Steven G Dec 09 '18 at 16:13

1 Answers1

1

This should do it for you:

df["c3"] = df.apply(lambda row: function(row["c1"], row["c2"]), axis=1)
griggy
  • 446
  • 4
  • 7