两点说明:处理数据用pandas,生成数据用numpy,在处理json数据的时候由于数据连贯,我们不能按行读取,因此需要 使用pandas直接读取,可以加快读取速度
import json
dt = {'name': 'Gage', 'age': 25}
print(json.dumps(dt))
sdt = '{"name": "Gage", "age": 25}'
print(json.loads(sdt))
with open(r'C:\Users\Gage\Desktop\新建文件夹 (2)\qinghai-gejie-20200221.txt', 'r', encoding='utf-8') as f:
print(json.load(f))
with open('new.txt', 'w') as f:
json.dump(dt, f)
pickle 可以保密一些数据,但被破环将不能读取
import pickle
dt = {'name': 'Gage', 'age': 25}
with open('new.txt', 'wb') as f:
pickle.dump(dt, f)
with open('new.txt', 'rb') as f:
print(pickle.load(f))
pdt = pickle.dumps(dt)
print(pdt)
print(pickle.loads(pdt))
with open(r'C:\Users\Gage\Desktop\新建文件夹 (2)\qinghai-gejie-20200221.txt', 'r', encoding='utf-8') as f:
print(pd.read_json(f))