1

I have the following dataframe:

df = pd.DataFrame([{'answers': ['No'], 'questionId': 'applicationSubmitted'}, {'answers': ['NOT_READY_TO_ENROLL'], 'questionId': 'status'}, {'answers': ['Intro'], 'questionId': 'salesProcessReached'}, {'answers': [True], 'questionId': 'noTimeToCoverCurrentPlan'}, {'answers': [''], 'questionId': 'currentPlan'}, {'answers': ['No'], 'questionId': 'scheduleFollowUp'}])

Upon applying pivot function df.pivot(columns='questionId') , i get the following table: Too many extra rows

How can I tweak the pivot to have only 1 row show up for all answers, with only 1 row for headers instead of two.

Thank you

1 Answers1

1

Use pivot_table with aggfunc as max:

df.pivot_table(columns='questionId', aggfunc=max)

Output:

questionId applicationSubmitted currentPlan noTimeToCoverCurrentPlan salesProcessReached scheduleFollowUp                 status
answers                    [No]          []                   [True]             [Intro]             [No]  [NOT_READY_TO_ENROLL]
U13-Forward
  • 69,221
  • 14
  • 89
  • 114