I have a ".data" file containing these two sample rows below. The first row denotes json and the second row denotes tsv. I would like to convert the json to a python dictionary and the tsv lines into a python dictionary and then output both into a dataframe using a generator.
###SAMPLE LINES of ".DATA" FILE###
{"Book": "American Horror", "Author": "Me", "date": "12/12/2012", publisher": "Fox"
Sports Law Some Body 06/12/1999 Random House 1000
import json
def generator(file):
for row in open(file, encoding="ISO-8859-1"):
print(row)
if "{" in row:
yield json.loads(row)
else:
###I don't know where to begin with the tsv data
###tsv data must fit under column names of json data
for tsv in row:
yield tsv
file = ".data_file"
with open(file,'r') a some_stuff:
df = pd.DataFrame(data=generator(some_stuff))
df
'''