【发布时间】:2021-05-08 22:13:32
【问题描述】:
我有一个包含 1000 行的 json,在这里我不会让你厌烦,但这是数据集的一个简单示例。
{
"places": [
{
"place_name": "123 YOU N ME PRESCHOOL",
"address": "809 W DETWEILLER DR STE A",
"city": "PEORIA",
"state": "IL",
"zip": "61614",
"geo_location": "40.89564657,-89.60566821",
"data": {}
},
{
"place_name": "123 YOU N ME PRESCHOOL",
"address": "809 W DETWEILLER DR STE A",
"city": "PEORIA",
"state": "IL",
"zip": "61615",
"geo_location": "40.78878653,-89.605669034",
"data": {}
},
{
"place_name": "18144 GLEN TERRACE ST.",
"address": "18144 GLEN TERRACE ST.",
"city": "LANSING",
"state": "IL",
"zip": "60438",
"geo_location": "41.565952019,-87.556316006",
"data": {}
}
]
}
如您所见,前两个地方几乎相同,但它们的拉链和地理位置不同,因此它们不是重复的。我目前有一个脚本,它只查看被重复的 place_name,但这会返回我实际上并不重复的地方。本质上,我希望我的脚本查看每一行,如果一行与另一行相同,则删除该行。 到目前为止,这是我的代码。
import collections
import pandas as pd
places = pd.read_json("test.json")
place_names = [item['place_name'] for item in places['places']]
print([item for item, count in collections.Counter(place_names).items() if count > 1])
【问题讨论】:
-
this post 回答你的问题了吗?
-
@user696969 不一定。这些都涉及一堆元组和列表以及散列,但我想知道是否有更简单的方法。
-
就是这样。
标签: python json pandas dataframe