convert columns to rows and row index as multiple rows in df
Answers
Answered by
8
Answer:
Pandas provides a convenient way to handle data and its transformation. Let’s see how can we convert a column to row name/index in Pandas.
Create a dataframe first with dict of lists.
# imporing pandas as pd
import pandas as pd
# Creating a dict of lists
data = {'Name':["Akash", "Geeku", "Pankaj", "Sumitra","Ramlal"],
'Branch':["B.Tech", "MBA", "BCA", "B.Tech", "BCA"],
'Score':["80","90","60", "30", "50"],
'Result': ["Pass","Pass","Pass","Fail","Fail"]}
# creating a dataframe
df = pd.DataFrame(data)
df
Answered by
2
Answer:
. ............. see attachment for ans
Attachments:
Similar questions