One liner for batch changes in pandas column

  pandas, python, replace, string

I have a pandas dataframe, with 10 columns and thousands of rows.
The first column is the name of website users, for example:

  Name ...
0 Alex
1 Fred
2 John
3 Chloe
...

I want to change this first column into this:

  Name ...
0 Hi! Alex, mind calling me at 8 p.m.?
1 Hi! Fred, mind calling me at 8 p.m.?
2 Hi! John, mind calling me at 8 p.m.?
3 Hi! Chloe, mind calling me at 8 p.m.?
...

Here, the number 8 will be free input.

In a word, the target string template might be: "Hi! {}, mind calling me at {} p.m.?" – The first placeholder will be the word in the corresponding cell, and the second one for the input number.

I thought of iterating over all rows and manually change the string, but this looks awful and non-pythonian way.

I would like to know if there is a one-liner to do this.

Source: Python Questions

LEAVE A COMMENT