user53526356
user53526356

Reputation: 968

Iterate over lists in dataframe cells

I have a dataframe where some cells contain lists, and I want to iterate through each item in each list with a simple print statement.

      Date     Names
0  2018_Q1     ['Faye', 'Mark', 'Shay', 'Alex']
1  2019_Q1     ['Pete', 'Alan', 'Stan', 'Faye']
2  2019_Q2     Mike

For example, the output should look something like:

2018_Q1
- Faye
- Mark
- Shay
- Alex

2019_Q1
- Pete
- Alan
- Stan
- Faye

2019_Q2
- Mike

How do I achieve this?

Upvotes: 1

Views: 34

Answers (1)

BENY
BENY

Reputation: 323226

Try with

out =  df.Date + ':' + df.Names.str.join(',')

Upvotes: 1

Related Questions