您可以使用
json_normalize:
import jsonfrom pandas.io.json import json_normalizewith open('myJson.json') as data_file: data = json.load(data_file)df = json_normalize(data, 'locations', ['date', 'number', 'name'], record_prefix='locations_')print (df) locations_arrTime locations_arrTimeDiffMin locations_depTime 06:32 1 06:37 1 06:40 2 08:24 1 locations_depTimeDiffMinlocations_name locations_platform 0 Spital am Pyhrn Bahnhof 2 1 0 Windischgarsten Bahnhof 2 2 Linz/Donau Hbf 1A-B locations_stationIdx locations_track number name date 0 0 R 3932 R 3932 01.10.2016 1 1 R 3932 01.10.2016 2 22 R 3932 01.10.2016
编辑:
你可以用
read_json与解析
name的
Dataframe构造函数,并最后
groupby与应用
join:
df = pd.read_json("myJson.json")df.locations = pd.Dataframe(df.locations.values.tolist())['name']df = df.groupby(['date','name','number'])['locations'].apply(','.join).reset_index()print (df) date name number locations0 2016-01-10 R 3932 Spital am Pyhrn Bahnhof,Windischgarsten Bahnho...
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)