I'm trying to read a json file as a pandas dataframe and convert it to a numpy array:
sample.json = [[["1", "2"], ["3", "4"]], [["7", "8"], ["9", "10"]]]
-------------------------------------------------------------------
df = pd.read_json('sample.json', dtype=float)
data = df.to_numpy()
print(df)
print(data)
However, this yields a numpy array of python lists:
0 1
0 [1, 2] [3, 4]
1 [7, 8] [9, 10]
[[list(['1', '2']) list(['3', '4'])]
[list(['7', '8']) list(['9', '10'])]]
When I want it to look like this:
[[1, 2], [3, 4]],
[[7, 8], [9, 10]]
I understand this can be accomplished by iterating over the array manually, but I'd rather avoid doing that as the data set is quite large. I have read that using df.values() is not encouraged. Any help appreciated