Python 将数据从Yelp API导出到csv文件

Python 将数据从Yelp API导出到csv文件,python,csv,import,yelp-fusion-api,Python,Csv,Import,Yelp Fusion Api,我是一个尝试使用yelpapi的初学者,我已经能够获取我需要的信息,但是我不知道如何只将地址的一部分导出到我的csv文件中。这是我正在使用的代码: **Convert the JSON string to a dictionary* business_data = response.json() c = csv.writer(open('testing.csv', 'a'), lineterminator ='\n') for biz in business_data['businesses

我是一个尝试使用yelpapi的初学者,我已经能够获取我需要的信息,但是我不知道如何只将地址的一部分导出到我的csv文件中。这是我正在使用的代码:

**Convert the JSON string to a dictionary*

business_data = response.json()
c = csv.writer(open('testing.csv', 'a'), lineterminator ='\n')

for biz in business_data['businesses']:

    c.writerow([biz['name'], biz['location'], biz['phone'], biz['url']])

在最后一行代码中,在for循环中,我希望能够以“location”的特定元素为目标,如下所示:

#c.writerow([biz['name'], biz['address1'], biz['city'], biz['state'], biz['zip_code'], biz['phone'], biz['url']])
businesses[x].location.address1 
businesses[x].location.address2 
businesses[x].location.city 
在Yelp网站上,它显示我可以针对这些细节,但我似乎不知道如何使用c.writerow()

Yelp表明我可以像这样瞄准这些目标:

#c.writerow([biz['name'], biz['address1'], biz['city'], biz['state'], biz['zip_code'], biz['phone'], biz['url']])
businesses[x].location.address1 
businesses[x].location.address2 
businesses[x].location.city 

从响应来看,biz['location']是一个python字典,意味着它由键、值对组成

您可以通过打印
类型(biz['location'])
来验证这一点。要回答您的问题,您只需调用dict键并将值写入文件

c.writerow([biz['name'], biz['location']['address1'], biz['location']['city'], biz['location']['state'], biz['location']['zip_code'] biz['phone'], biz['url']])
在最后一行代码中,在for循环中,我希望能够以“location”的特定元素为目标,如下所示:那么这样做有什么错?你在挣扎哪一部分?