Python Forum
Converting a json file to a dataframe with rows and columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting a json file to a dataframe with rows and columns
#1
Hey all,

I am trying to convert a json file into a dataframe.

import pandas as pd 
import os 
from pandas.io.json import json_normalize

data = []

path_to_json = '/Users/macbook/Desktop/Saveddata'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
for i in range(0,len(json_files)):
    file = pd.read_json(r'/Users/macbook/Desktop/Saveddata/' + str(json_files[i]))

file2 = file.iloc[113:]
file2.iloc[0]
output:
game-data    [{'meta': {'user_id': '178054', 'level_id': 1,...
In the example above, I would like 'user_id' to be a column header, 'level_id' to be a column header etc. '170854' would be the first row of the first column and '1' would be the first row of the second column.

How can I achieve this?

I would be so grateful for a helping hand!
Reply


Messages In This Thread
Converting a json file to a dataframe with rows and columns - by eyavuz21 - Jan-28-2023, 08:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 239 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Converting column of values into muliple columns of counts highland44 0 260 Feb-01-2024, 12:48 AM
Last Post: highland44
  Converting .txt to .csv file SunWers 21 12,153 Jan-20-2024, 10:03 AM
Last Post: Larz60+
  Create Choices from .ods file columns cspower 3 622 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 771 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Create csv file with 4 columns for process mining thomaskissas33 3 768 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  Python Script to convert Json to CSV file chvsnarayana 8 2,552 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,150 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Reading Specific Rows In a CSV File finndude 3 1,003 Dec-13-2022, 03:19 PM
Last Post: finndude
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,898 Dec-12-2022, 08:22 PM
Last Post: jh67

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020