Categories
Development

Separator between strings from JSON

I am trying to save text file with string values from JSON array (Pandas library), but I am strugling to separate them with comma sign. What I want achieve is this:

0, 0, 0
1,    0,   5
2,    0,  10
3,    0,  15
4,    5,   0
5,   10,   0
6,   15,   0
7,   15,   5
8,   15,  10
9,   15,  15
10,  10,  15
11,   5,  15

while saving the string output to file gives me this (0 and 1 are numbers of columns, which I don’t want in file):

0     1
0    0   0
1    0   5
2    0  10
3    0  15
4    5   0
5   10   0
6   15   0
7   15   5
8   15  10
9   15  15
10  10  15
11   5  15

This is my code so far:

import numpy as np
import pandas as pd

points = np.array([(0.0, 0.0), (0.0, 5.0), (0.0, 10.0), (0.0, 15.0), (5.0, 0.0), (10.0, 0.0), (15.0, 0.0), (15.0, 5.0), (15.0, 10.0), (15.0, 15.0), (10.0, 15.0), (5.0, 15.0)])

df = pd.DataFrame(points)
df.to_json('data.json')

y = pd.read_json(r'data.json')

file = open("result.inp", "w")

file.write(str(y))
file.close()

Some advices?

Leave a Reply

Your email address will not be published. Required fields are marked *