首页 > 解决方案 > 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.

标签: python

解决方案


推荐阅读