【441】JSON format
Ref: json -- JSON encoder and decoder
JSON(JavaScript Object Notation) can help us to see data more intuitive. Example:
import json
>>> a = {"hobbies":{"balls":"basketball, volleyball", "others":"watching movies"},"name":{"first_name":"Alex", "last_name":"Lee"}, "age":20, "height":183}
>>> print(json.dumps(a, indent = 4))
{
"hobbies": {
"balls": "basketball, volleyball",
"others": "watching movies"
},
"name": {
"first_name": "Alex",
"last_name": "Lee"
},
"age": 20,
"height": 183
}
快速读取相应的 str,转为 json 格式,类似字典,不过可以存储在字符串里面
# 从 pandas.dataframe 里面读取对应的字符串 str2 = df_road.loc[0]['tag'] str2 # 将字符串解析,类似字典的形式 import json str_json = json.loads(str2) str_json

浙公网安备 33010602011771号