-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

1
  • Can you post expected output? Commented Dec 4, 2019 at 6:51

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

3 Comments

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..
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()))
@MichaelWu you can read this up 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 stackoverflow.com/a/52637531/12128167, try it out.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.