python - How to filter data from JSON in python
问题描述
I am working in pyton and using a JSON file and pulling info from it and sending to a csv file, the code I am using is as follows:
import csv
import json
csv_kwargs = {
'dialect': 'excel',
'doublequote': True,
'quoting': csv.QUOTE_MINIMAL
}
inpfile = open('checkin.json', 'r', encoding='utf-8')
outfile = open('checkin.csv', 'w', encoding='utf-8')
writer = csv.writer(outfile, **csv_kwargs, lineterminator="\n")
for line in inpfile:
d = json.loads(line)
writer.writerow([d['business_id'],d['date']])
inpfile.close()
outfile.close()
checkin.json has a date element that has both date of'MM:DD:YYYY' and time of 'HH:MM:SS'. My question is how do you code this to keep the date, but not the time being that they are in the same element.
解决方案
推荐阅读
- ajax - 使用ajax登录表单django
- html - 重新定位相对子 div 时调整父 div 的高度
- python - pandas - 将列名称作为值
- typescript - 将类型声明与条件类型合并
- python - ImportError:没有名为 mqtt.client 的模块错误 [paho-mqtt]
- sql - 获取rails中集合的关系
- json - 将 dict 的 dict 转换为数据框
- java - 使用 lombok 时是否应该实例化一个字段
- typescript - 在 TypeScript 中导入类型定义的不同方法?
- html - HTML CSS响应改变浏览器大小的位置