0

I know this may have been asked somewhere already but I could not find the questions/answers (maybe because I'm new to pandas). So here it goes:

If I wanted to calculate a new column from a pandas dataframe, I could do something like this:

df['col_b'] = df.col_a + 100

But I would not be able to do something like this:

df['col_c'] = str(df.col_a) + 'c'

I know I could use the apply() method and pass a lambda or a function. But this usually seems very slow on large datasets (a million rows) and I don't have access to the index value. Is there a better (faster) way to do this type of manipulation?

Edit:

I know I provided a simple string concatenation problem. But I'm interested in a more generic best practice for even more complex situations like datetime manipulation.

swbandit
  • 1,986
  • 1
  • 26
  • 37

0 Answers0