|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我的代码如下 ,但运行不了,请求大师帮忙解决或是修改我的代码
rr = '''势*/var Data_grandTotal = [{"name":"华夏成长混合","data":[[1664467200000,0],[1665331200000,-1.54],[1680192000000,-10.12]]},{"name":"同类平均","data":[[1664467200000,0],[1665331200000,-1.66],[1680192000000,2.30]]},{"name":"沪深100","data":[[1664467200000,0],[1665331200000,-2.21],[1680192000000,6.47]]}];/*同'''
result = re.findall(r'var Data_grandTotal = \[(\{.*?\})\];', rr)
data_ljsy = json.loads(result )
data_dic = {} # 获取数据部分并转换为字典形式
for item in data_ljsy:
data_dic[item['name']] = item['data'][1]
data_dic[['时间']] = item['data'][0]
df = pd.DataFrame(data_dic)
print(df)
我想要的结果:
时间 华夏成长混合 同类平均 沪深100
1664467200000 0 0 0
1665331200000 -1.54 -1.66 -2.21
1680192000000 -10.12 2.3 6.47
import re
import json
import pandas as pd
rr = '''势*/var Data_grandTotal = [{"name":"华夏成长混合","data":[[1664467200000,0],[1665331200000,-1.54],[1680192000000,-10.12]]},{"name":"同类平均","data":[[1664467200000,0],[1665331200000,-1.66],[1680192000000,2.30]]},{"name":"沪深100","data":[[1664467200000,0],[1665331200000,-2.21],[1680192000000,6.47]]}];/*同'''
result = re.findall(r'var Data_grandTotal = (\[.*?\]);', rr)
data_ljsy = json.loads(result[0])
data_dic = {}
for item in data_ljsy:
for data in item['data']:
if data[0] not in data_dic:
data_dic[data[0]] = {}
data_dic[data[0]][item['name']] = data[1]
df = pd.DataFrame(data_dic).T.reset_index()
df.columns.name = None
df.rename(columns={"index": "时间"}, inplace=True)
print(df)
|
|