54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
|
|
import pandas as pd
|
|
|
|
# 文件路径
|
|
file_path = r'/root/.openclaw/workspace-xiaoyan/business_knowledge/L2单词表/L2知识库-三级+A2.xlsx'
|
|
|
|
# 要添加的16个单词
|
|
words_to_add = [
|
|
('supper', 'n.', '晚餐'),
|
|
('cafeteria', 'n.', '食堂'),
|
|
('tidy up', 'v.', '收拾'),
|
|
('all sorts of', 'phr.', '各种各样的'),
|
|
('all the time', 'phr.', '一直'),
|
|
('bring back', 'v.', '拿回'),
|
|
('turn off', 'v.', '关掉'),
|
|
('cabinet', 'n.', '橱柜'),
|
|
('get back', 'v.', '拿回'),
|
|
('costume', 'n.', '服装'),
|
|
('equipment', 'n.', '装备'),
|
|
('explorer', 'n.', '探险家'),
|
|
('upload', 'v.', '上传'),
|
|
('dot', 'n.', '点'),
|
|
('successful', 'adj.', '成功的'),
|
|
('give back', 'v.', '归还'),
|
|
]
|
|
|
|
# 按字母顺序排序
|
|
words_to_add_sorted = sorted(words_to_add, key=lambda x: x[0].lower())
|
|
|
|
# 读取文件
|
|
df = pd.read_excel(file_path)
|
|
|
|
print(f"现有行数: {len(df)}")
|
|
|
|
# 创建新行DataFrame
|
|
new_rows = pd.DataFrame(words_to_add_sorted, columns=['单词', '词性', '中文释义'])
|
|
|
|
# 合并
|
|
df_updated = pd.concat([df, new_rows], ignore_index=True)
|
|
|
|
# 按字母顺序排序
|
|
df_updated = df_updated.sort_values(by='单词', key=lambda x: x.astype(str).str.lower())
|
|
|
|
# 保存
|
|
df_updated.to_excel(file_path, index=False)
|
|
|
|
print(f"\n添加完成!")
|
|
print(f"添加了 {len(words_to_add)} 个新单词")
|
|
print(f"更新后总行数: {len(df_updated)}")
|
|
|
|
print("\n新添加的单词(按字母顺序):")
|
|
for i, (word, pos, meaning) in enumerate(words_to_add_sorted, 1):
|
|
print(f"{i:2d}. {word:20s} {pos:8s} {meaning}")
|