Advertisement
wagner-cipriano

Pandas example

Mar 8th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Mar  8 20:47:17 2017
  4. @author: wagner
  5. REF: http://pbpython.com/pandas-list-dict.html
  6. """
  7. import pandas as pd
  8. import numpy as np
  9. from io import StringIO
  10.  
  11. txtFile = StringIO(u"0.      0.0007  0.001   0.001   0.0006\n0.      0.001   0.001   0.0008  0.0006\n0.001   0.001   0.001   0.0009  0.0007\n0.001   0.0013  0.001   0.0008  0.0006\n0.002   0.001   0.001   0.0008  0.0007")
  12. data = np.loadtxt(txtFile)
  13. StructData = {}
  14. Label = ['Label1', 'Label2', 'Label3', 'Label4', 'Label5']
  15.  
  16. Columns = data.shape[1]
  17. for c in xrange(Columns):
  18.     StructData[Label[c]] = list(data[:,c])
  19. #print StructData
  20.  
  21. df = pd.DataFrame.from_dict(StructData)
  22. print '\n'*3, df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement