[英]How to select duplicate key values from json file and make unique in Python
我正在使用 API 生成的 json 文件,其中包含字典。 在“元素字典”(在 json 文件中)有“路徑”鍵,它有一個值。 一些“路徑”值是重復的,但我想讓它們獨一無二,例如通過在“路徑”值的末尾添加 /random_alphabets 或 /random_numbers 。 我正在使用 pandas 和 json_normalize 來執行此操作,但是在制作數據框后,當我規范化“元素字典”以獲取路徑時,它只顯示 50 個“路徑”(json 文件中的元素字典中有 243 個路徑)。
任何幫助,將不勝感激。 謝謝!
以下是我的代碼:
import pandas as pd
from pandas.io.json import json_normalize
import json
with open('structuredData-15.json') as json_data:
text = json.load(json_data)
text
test = json_normalize(text)
test
ele = test['elements'][0]
elements = json_normalize(ele)
elements
elements['Path']
以下是我正在使用的 json 文件的鏈接: https://drive.google.com/drive/folders/1G4eaHRa8IPyGrtQKEa_rbU0CupJih7_4?usp=sharing
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.