I have a JSON file named stocks.json that looks as follows (note the lack of square brackets in the source file):
{"MSFT": {"exchange": "Nasdaq", "price": 275.79}, "FB": {"exchange": "Nasdaq", "price": 320.22}, "TSLA": {"exchange": "Nasdaq", "price": 990.83}, "GE": {"exchange": "Nasdaq", "price": 83.20}} I would like to transform this data into a Pandas dataframe that looks as follows:
symbol exchange price MSFT Nasdaq 275.79 FB Nasdaq 320.22 TSLA Nasdaq 990.83 GE NYSE 83.20 My attempt is:
import pandas as pd stock_data = pd.read_json('stocks.json', lines=True) stock_data_normalized = pd.json_normalize(stock_data) Unfortunately, I get the following when calling stock_data_normalized:
0 1 2 3 Any assistance would be most appreciated. Thanks!