@rock_bt wrote:
Hey All,
I want to read JSON file, can someone tell what is wrong in the below code:import numpy as np import pandas as pd import zipfile import json from pandas.io.json import json_normalize JSON_COLUMNS = ['device', 'geoNetwork', 'totals', 'trafficSource'] df1 = pd.read_csv(zipfile.ZipFile('t2.zip').open('t2.csv'), converters={column: json.loads for column in JSON_COLUMNS},dtype={'fullVisitorId': 'str'}) for column in JSON_COLUMNS: column_as_df = json_normalize(df1[column]) column_as_df.columns = [f"{column}.{subcolumn}" for subcolumn in column_as_df.columns] df1 = df1.drop(column, axis=1).merge(column_as_df, right_index=True, left_index=True) df1.head()
Posts: 1
Participants: 1