您可以尝试将您的代码替换jn = pd.json_normalize(r)
为以下代码,以便将列下的嵌套 json 列表扩展examInformation
为单独的行:
使用.explode()
+ pd.Series
:
jn = jn.drop('examInformation', axis=1).join(jn.explode('examInformation').apply(lambda x: pd.Series(x['examInformation']), axis=1))
或使用:.explode()
+pd.DataFrame
以加快执行速度:
jn_exp = jn['examInformation'].explode()
jn = jn.drop('examInformation', axis=1).join(pd.DataFrame(jn_exp.tolist(), index=jn_exp.index))
结果:
examInformation
请参阅下面最右侧列中的扩展信息:
print(jn)
vehicleCategory type id name lat lon examInformationAllLocations.allAttempts examInformationAllLocations.successfulAllAttemptsPercentage contactInformation.streetName contactInformation.houseNumber contactInformation.houseNumberExtension contactInformation.zipCode contactInformation.city contactInformation.website contactInformation.email contactInformation.phone1 contactInformation.phone2 contactInformation.kvk contactInformation.drivingSchoolNumber contactInformation.tradeAssociations lessonTypes.Theorieopleidingen lessonTypes.Beroepsopleidingen lessonTypes.Bijzonderheden lessonTypes.Praktijkopleidingen cbrLocation cbrLocationShortName cbrLocationLink locationSuccessfulPercentage drivingSchoolSuccessfulPercentage firstAttempts successfulFirstAttemptsPercentage retakeAttempts successfulSecondAttemptsPercentage
0 B rijschool 11764 Rijschool Baron 51.694322 5.287478 81 43 Amperestraat 28 5223CV 'S-HERTOGENBOSCH 06 44 30 30 81 743056970000 1666U0 [] [] [] [] Examencentrum Tiel Tiel /nl/service/nl/artikel/examencentrum-tiel-1.htm 57 100 0 0 1 100
0 B rijschool 11764 Rijschool Baron 51.694322 5.287478 81 43 Amperestraat 28 5223CV 'S-HERTOGENBOSCH 06 44 30 30 81 743056970000 1666U0 [] [] [] [] Examencentrum Den Bosch Den Bosch /nl/service/nl/artikel/examencentrum-den-bosch.htm 54 42 30 43 50 42