An increasing number of companies are collaborating with AerisWeather. In turn, we continue to deliver improvements and widen the scope of our weather data offerings. As companies grow and expand, so does the amount of data they generate. Naturally, leveraging this data effectively can be challenging.
One of the most popular methods of analysis is via CSV file. The format is commonly associated with Excel spreadsheets and is popular in data analysis. The downside of CSV files is that they are not as versatile for mass distribution as other formats. This is why AerisWeather distributes data in JSON or GeoJSON file formats, which can then be converted to CSV – but the translation process can appear daunting. In this post, we will walk through the following:
JSON:
JavaScript Object Notation, or JSON for short, is the primary file format AerisWeather uses to export data to clients. This format, as the name implies, is identical to the code for creating JavaScript objects. Because of this, a JavaScript application can easily convert JSON data to JavaScript objects.
GeoJSON:
AerisWeather also exports data in the form of GeoJSON. GeoJSON is a more focused JSON format, used for encoding various geographic data structures. GeoJSON data can be found almost anywhere mapping is required. Services like Google Maps primarily use this data format to deliver specific geospatial data for all kinds of scenarios. GeoJSON generally makes use of one or multiple coordinate points in the form of different data types, typically called Features. These range from a singular coordinate point, lines containing multiple coordinate points, or even full geospatial areas enclosed by these lines.
CSV:
Comma-Separated Values, also referred to as a CSV file, is a format commonly used in numerous situations. A CSV, as the name implies, contains values separated by commas in a plain text format. This file type is typically associated with Microsoft Excel – likely because Microsoft Excel and programs like it, such as Google Sheets, are programs that are created to interpret and manipulate CSV files.
We deliver our data in JSON or GeoJSON instead of CSV for a few primary reasons.
It’s worth noting that JSON/GeoJSON can have a larger file size compared to CSV files; however, this is a small price to pay to have the opportunity to deliver complete and complex datasets to clients across the globe.
Although we provide our data in JSON and GeoJSON format, we understand not all of our clients use JSON-compatible programs. The following examples will show you how to easily translate our data to a more universal CSV format.
To follow along with these examples, you will need the following:
This first method will make use of Python and pandas, a powerful Python library often used for data analysis. This method is straightforward and only takes a few steps:
python --version
py
import pandas as pd
pandas __version__
result = pd.read_json(‘json_name.json’, orient=’records’, typ=’frame’)
fields = [‘field1’, field2.subfield1, field2.subfield2,...]
df = pd.json.normalize(results[‘superfield’])
output = df[fields]
output.to_csv(‘output.csv’)
Conversion to CSV can also be completed through Microsoft Excel. This process can be slightly more complicated but offers the ability to see your data during the conversion. For this example, we will be investigating JSON results from the AerisWeather conditions endpoint.
This blog reviewed the differences between JSON, GeoJSON, and CSV file formats, the reasons why AerisWeather chooses to deliver its data in JSON format, and how to convert our JSON/GeoJSON data to a CSV format. Use this information to cut down on time and analyze large datasets more efficiently – and as always, if you have any questions, reach out – we’re here to help!
No comments yet.
Be the first to respond to this article.