How can I output multiple lines of json in Python in the form of a data frame?

Asked 2 years ago, Updated 2 years ago, 91 views

Types stored in json files

# test.json
{key_a1:value_a1, key_a2:value_a2, key_a2:value_a3}\n
{key_a1:value_b1, key_a2:value_b2, key_a2:value_b3}\n
{key_a1:value_c1, key_a2:value_c2, key_a2:value_c3}\n
{key_a1:value_d1, key_a2:value_d2, key_a2:value_d3}\n
.
.
.

As shown above, the test.json file has the same key value structure in the form of multiple lines of dictionaries. When you call this to scalar and read it, it looks like below.

valdf=spark.read.json("/home/test/data/test.json")
df.show()

.

Can I read the Json file in data frame form at once in Python? Also, can you select the key value at once in a dictionary structure with multiple lines but the same structure and sort it into the desired form? For example, The key values of other dictionaries in key_a2 are organized into data frames with columns

python json scala pandas dataframe

2022-09-20 22:03

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.