I'm new to Python. Now I have a JSON file. I need first read the file in Python and then do something (make a two way table, etc.) with it. I was able to do this:
import json
with open('DrateLspan.json') as f:
file = json.load(f)
for i in file:
print(i['Year'])
However, since I need extract the data from JSON and do something more, I do not want to stop at the "print" step. I tried ye = file['Year'] but it shows "string indices must be integers, not str". Can anyone help me with this? I want use the data in the JSON file.
Below this the first several lines of my JSON file:
[
{
"Year": 2015,
"Race": "All Races",
"Sex": "Both Sexes",
"Average Life Expectancy (Years)": "",
"Age-adjusted Death Rate": 733.1
},
{
"Year": 2014,
"Race": "All Races",
"Sex": "Both Sexes",
"Average Life Expectancy (Years)": 78.9,
"Age-adjusted Death Rate": 724.6
},
{
"Year": 2013,
"Race": "All Races",
"Sex": "Both Sexes",
"Average Life Expectancy (Years)": 78.8,
"Age-adjusted Death Rate": 731.9