Construct pandas DataFrame from list of tuples of (row,col,values)

后端 未结 3 1884
渐次进展
渐次进展 2020-12-04 09:44

I have a list of tuples like

data = [
(\'r1\', \'c1\', avg11, stdev11),
(\'r1\', \'c2\', avg12, stdev12),
(\'r2\', \'c1\', avg21, stdev21),
(\'r2\', \'c2\',          


        
3条回答
  •  失恋的感觉
    2020-12-04 10:24

    This is what I expected to see when I came to this question:

    #!/usr/bin/env python
    
    import pandas as pd
    
    
    df = pd.DataFrame([(1, 2, 3, 4),
                       (5, 6, 7, 8),
                       (9, 0, 1, 2),
                       (3, 4, 5, 6)],
                      columns=list('abcd'),
                      index=['India', 'France', 'England', 'Germany'])
    print(df)
    

    gives

             a  b  c  d
    India    1  2  3  4
    France   5  6  7  8
    England  9  0  1  2
    Germany  3  4  5  6
    

提交回复
热议问题