0

I have this data frame using python and this is the result I wanted after cleaned and analyzing the data

result from python

but I wanted in this format how can I do this in pandas python formt I eant

3
  • What did you have tried so far? Commented Jun 26, 2022 at 14:56
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jun 26, 2022 at 16:45
  • you can use melt or transpose. if you need more control of the matrix use pivot table Commented Jun 27, 2022 at 15:48

1 Answer 1

1

Hopefully this is what you are looking for.

df = pd.DataFrame({'status': ['cancelled', 'failed', 'pending', 'ticketed'],
                   'new': [511, 5561, 105, 2115],
                   'atc': [97, 580, 10, 646]})



df1 = pd.melt(df, id_vars=['status'], value_vars=['new', 'atc'], value_name='value' ).sort_values('status')

print(df1)



   status variable  value
0  cancelled      new    511
4  cancelled      atc     97
1     failed      new   5561
5     failed      atc    580
2    pending      new    105
6    pending      atc     10
3   ticketed      new   2115
7   ticketed      atc    646
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.