-1

If my file content is (filename:test):

00001069: 04 33 c0 eb 42 53 8b 1e 6b 00 6a 04 6a 02 6a 00

00001078: 6a 02 68 00 00 00 70 68 38 30 00 10 ff 15 08 20

How do I read the file into content

ex :

df = pd.DataFrame(content,'test')

thank you

Rajith Thennakoon
  • 3,975
  • 2
  • 14
  • 24
Michael Wu
  • 13
  • 4

2 Answers2

0

You can use pd.read_csv

import pandas as pd
data = pd.read_csv('test', sep=" ", header=None)
print(data)

Gives you,

          0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16
0  00001069:  04  33  c0  eb  42  53  8b  1e  6b   0  6a   4  6a   2  6a   0
1  00001078:  6a   2  68  00   0   0  70  68  38  30  00  10  ff  15  08  20

You may label the columns too,

data.columns = ["Code", "Elem 1", "Elem 2", "Elem 3", "Elem 4", "Elem 5", "Elem 6", "Elem 7", "Elem 8",
                "Elem 9", "Elem 10", "Elem 11", "Elem 12", "Elem 13", "Elem 14", "Elem 15", "Elem 16"]
print(data)

Which gives you,

        Code Elem 1  Elem 2 Elem 3  ... Elem 13  Elem 14  Elem 15 Elem 16
0  00001069:     04      33     c0  ...      6a        2       6a       0
1  00001078:     6a       2     68  ...      ff       15       08      20
Sin Han Jinn
  • 574
  • 3
  • 18
  • but i get **DtypeWarning: Columns (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) have mixed types. Specify dtype option on import or set low_memory=False.**....how can i set types.. – Michael Wu Dec 04 '19 at 08:43
  • in Repl.it website is "OK" `contents =[datas,"TEST"] results=[] results.append(contents) df = pd.DataFrame(data=results)` but in Microsoft ML get Error : NotImplementedError('Python Bridge conversion table not implemented for type [{0}]'.format(value.getType())) – Michael Wu Dec 04 '19 at 08:57
  • @MichaelWu you can read this up https://stackoverflow.com/a/27232309/12128167. It will help for your DtypeWarning. I have not used Microsoft ML, you meant Azure ML? This question leads to your error https://stackoverflow.com/a/52637531/12128167, try it out. – Sin Han Jinn Dec 05 '19 at 06:20
0

Use pandas as stated above by Hj Sin You can visit this site to read more about pandas and how to import various type of data https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html

fessyadedic
  • 101
  • 1
  • 3