- Hands-On Artificial Intelligence for IoT
- Amita Kapoor
- 203字
- 2021-07-02 14:02:00
JSON files with the pandas module
JSON strings or files can be read with the pandas.read_json() function, which returns a DataFrame or series object. For example, the following code reads the zips.json file:
df = pd.read_json(os.path.join(data_folder,data_file), lines=True)
print(df)
We set lines=True because each line contains a separate object in JSON format. Without this argument being set to True, pandas will raise ValueError. The DataFrame is printed as follows:
_id city loc pop state 0 1001 AGAWAM [-72.622739, 42.070206] 15338 MA 1 1002 CUSHMAN [-72.51565, 42.377017] 36963 MA ... ... ... ... ... ... 29351 99929 WRANGELL [-132.352918, 56.433524] 2573 AK 29352 99950 KETCHIKAN [-133.18479, 55.942471] 422 AK [29353 rows x 5 columns]
To save the pandas DataFrame or series object to a JSON file or string, use the Dataframe.to_json() function.
More information for both of these functions can be found at these links: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_json.html and https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_json.html.
While CSV and JSON remain the most popular data formats for IoT data, due to its large size, it is often necessary to distribute data. There are two popular distributed mechanisms for data storage and access: HDF5 and HDFS. Let's first learn about the HDF5 format.
推薦閱讀
- 大學計算機基礎:基礎理論篇
- Spark編程基礎(Scala版)
- 手把手教你學AutoCAD 2010
- Hands-On Cloud Solutions with Azure
- 人工智能工程化:應用落地與中臺構建
- 機艙監測與主機遙控
- Implementing Splunk 7(Third Edition)
- 悟透AutoCAD 2009完全自學手冊
- 菜鳥起飛系統安裝與重裝
- Apache源代碼全景分析(第1卷):體系結構與核心模塊
- 電腦上網入門
- 21天學通Linux嵌入式開發
- 筆記本電腦維修之電路分析基礎
- Microsoft Dynamics CRM 2013 Marketing Automation
- ADuC系列ARM器件應用技術