#json文件:javascript object notation
import numpy as np
import pandas as pd
t_data={
"name":["唐浩","小王","老王","赵三","李四","王姐"],
"sex":["男","女","男","女","男","女"],
"year":[37,22,15,18,33,25],
"city":["成都","北京","上海","成都","深圳","北京"]
}
#读取json文件有两种方法
# 方法一:
# fj=open("json_data.json",encoding="utf-8")
# obj=fj.read()
# re=json.loads(obj)
# print(re)
# df=pd.DataFrame(re)
# print(df)
# 方法二:read_json()直接来,比上面要简单一些吧
# df_j=pd.read_json(open("json_data.json",encoding="utf-8"))
# print(df_j)
# #重新排序
# df_j.sort_index()
# print(df_j)
#to_json()函数对json数据进行存储,中文字符是编码了的,待解决
# df_j.to_json(open("json_data7.json","w",encoding="utf-8"),)
#Excel数据的读取与存储,,总结,要安装两个模块:xlrd,openpyxl,不然要报错,
#一、读取:read_excel(),开始要报错,没安装xlrd这个东西,安装后就行了。sheet_name=0第一个工作表,或“Sheet1”
# pd_r_excel=pd.read_excel("123.xlsx",sheet_name="Sheet1")
# print(pd_r_excel)
#二、存储:to_excel()
df_r_t_data=pd.DataFrame(t_data)
print(df_r_t_data)
df_r_t_data.to_excel("23456.xlsx",index=False) #openpyxl要安装这个模块,后就不报错了,
原文地址:https://www.cnblogs.com/yiyea/p/11441834.html