Jan-23-2017, 01:32 AM
Hey! Got an issue here. I need to read each line of .txt file as separate dictionary. Then to organize data in columns by the key of each dictionary.
my .txt file looks as follows:
{'Name': 'John', 'Age': 27, 'Score': 23}
{'Name': 'Peter', 'Age': 29, 'Score': 25}
I need to print it out as:
Name Age Score
John 27 23
Peter 29 25
so far, got to this peace of code:
with open('test.txt') as f:
data = f.readlines()
data = [x.strip() for x in data]
import pandas as pd
data = pd.DataFrame(data)
print(data)
which would only print:
0
0 {'Name': 'John', 'Age': 27, 'Score': 23}
1 {'Name': 'Peter', 'Age': 29, 'Score': 25}
Thank you and have a great day!
my .txt file looks as follows:
{'Name': 'John', 'Age': 27, 'Score': 23}
{'Name': 'Peter', 'Age': 29, 'Score': 25}
I need to print it out as:
Name Age Score
John 27 23
Peter 29 25
so far, got to this peace of code:
with open('test.txt') as f:
data = f.readlines()
data = [x.strip() for x in data]
import pandas as pd
data = pd.DataFrame(data)
print(data)
which would only print:
0
0 {'Name': 'John', 'Age': 27, 'Score': 23}
1 {'Name': 'Peter', 'Age': 29, 'Score': 25}
Thank you and have a great day!