He intentado convertir un json a csv, lo intenté directamente con la biblioteca csv
y también con pandas
, pero me dice TypeError
.
Éste es mi código:
import urllib2, json
url = "https://www.ncdc.noaa.gov/cdo-web/api/v2/stations"
token = 'CPxuwmGOwFTuTrPxPPWznbfnyHHEpHiZ'
req0 = urllib2.Request(url, headers={"token":token})
req = urllib2.urlopen(req0)
jdata = req.read()
import pandas as pd
import json
def jdata(df):
features = []
df.apply(lambda X: features.append(
geojson.Feature(geometry=geojson.Point((X["long"],
X["lat"],
X["elev"])),
properties=dict(name=X["name"],
description=unicode(X["description"].decode('utf8'))))
)
, axis=1)
with open('map.geojson', 'w') as fp:
geojson.dump(geojson.FeatureCollection(features), fp, sort_keys=True)
col = ["elevation", "mindata", "maxdata", "latitude", "name",
"datacoverage",
"id", "elevationUnit", "longitude"]
data = [jdata]
print (col)
print (data)