0

I have a DataFrame:

name time_start time_end
Albert 09:30 10:00
Smith 10:00 10:30
Green 10:30 11:00

I would like to add some message data as a appointment message:

Hello {name}. Your appointment will be held on {time_start} until {time_end}. Enjoy your day!

The message will be a new column in the DataFrame as shown below:

name time_start time_end message
Albert 09:30 10:00 Hello Albert. Your appointment will be held on 09:30 until 10:00. Enjoy your day!
Smith 10:00 10:30 Hello Smith. Your appointment will be held on 10:00 until 10:30. Enjoy your day!
Green 10:30 11:00 Hello Green. Your appointment will be held on 10:30 until 11:00. Enjoy your day!

Can you help me solve this problem using pandas?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • 1
    Simple string concatenation like [this answer](/a/11858532) `df['message'] = "Hello " + df['name'] + ". Your appointment will be held on " + df['time_start'] + " until " + df['time_end'] + ". Enjoy your day!"` – Henry Ecker Feb 15 '22 at 03:46
  • Or any of the many options of [this answer](/a/54298586) `df['message'] = df.agg(lambda x: f"Hello {x['name']}. Your appointment will be held on {x['time_start']} until {x['time_end']}. Enjoy your day!", axis=1)` – Henry Ecker Feb 15 '22 at 03:47
  • thank you so much for your feedback. Much appreciated – imbhaskara Feb 15 '22 at 09:26

0 Answers0