-1

I have a text file that's content is like bellow(I think it's a JSON object):

{"t":[1322352000,1322438400] , "o":[123,123], "h":[123,123], "l":[123,123], "c":[123,123]}

The problem is, I don't know the number of elements in each array, but they are equal as they are stock data. I like to make a .csv file that each array will fill one column of it. But have no idea and experience to doing that!

How may I approach this?

ayivima
  • 98
  • 3
Hasani
  • 3,543
  • 14
  • 65
  • 125
  • 1
    Possible duplicate of [How can I convert JSON to CSV?](https://stackoverflow.com/questions/1871524/how-can-i-convert-json-to-csv) – AGN Gazer Jun 19 '19 at 17:57
  • 1
    Try Convertio? That might help. It's an online tool that converts txt to csv – CodeHunter Jun 19 '19 at 17:57
  • 1
    Possible duplicate of [Convert tab-delimited txt file into a csv file using Python](https://stackoverflow.com/questions/10220412/convert-tab-delimited-txt-file-into-a-csv-file-using-python) – Meghshyam Sonar Jun 19 '19 at 18:05

1 Answers1

1

You can use pandas data frame to convert your file:

import pandas as pd
#df = pd.read_json('/path/to/infile.json')
df = pd.DataFrame({"t":[1322352000,1322438400] , "o":[123,123], "h":[123,123], "l":[123,123], "c":[123,123]})
df.to_csv('/path/to/outfile.csv', sep=",")
B.Gees
  • 1,125
  • 2
  • 11
  • 28