Skip to content

Commit 158b724

Browse files
增加转换元数据为json的脚本
1 parent 3cfdd05 commit 158b724

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

data.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

render_data.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""将元信息的`excel`数据转为`json`数据
2+
"""
3+
import json
4+
import pandas as pd
5+
import json
6+
7+
def render_list(s):
8+
str_list = s.strip("[]").split(",")
9+
return [ss.strip("' ") for ss in str_list]
10+
11+
if __name__ == "__main__":
12+
df = pd.read_excel('data.xlsx')
13+
json_list = df.to_dict(orient="records")
14+
res = [{
15+
**paper,
16+
**{
17+
"tag": render_list(paper['tag']),
18+
"authors": [] if pd.isna(paper['authors']) else render_list(paper['authors']),
19+
"company": "" if pd.isna(paper['company']) else paper['company']
20+
}}
21+
for paper in json_list]
22+
json.dump(res, open('data.json', "w", encoding="utf-8"))

0 commit comments

Comments
 (0)