How to turn raw data into matrix with row and column using python? -


for example, have raw data like:

jim  age  38 rose height 5'8 jim  salary 60000 jim  height 5'10 rose salary 40000 rose age   25 

how turn dataframe using python:

     age  height salary jim  38   5'10   60000 rose 25   5'8    40000 

many thanks!

assuming using pandas data frame, can use pivot function:

df.pivot(0, 1, 2)  #1     age  height  salary #0           # jim   38    5'10   60000 #rose   25     5'8   40000 

data used:

import pandas pd io import stringio  df = pd.read_csv(stringio("""jim  age  38 rose height 5'8 jim  salary 60000 jim  height 5'10 rose salary 40000 rose age   25"""), sep = "\s+", header=none) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -