39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
|
|
import pandas as pd
|
|
|
|
# 读取文件
|
|
file_path = r'/root/.openclaw/workspace-xiaoyan/business_knowledge/L2单词表/L2知识库-三级+A2.xlsx'
|
|
df = pd.read_excel(file_path)
|
|
|
|
print("文件列名:", df.columns.tolist())
|
|
print(f"现有行数: {len(df)}")
|
|
|
|
# 要添加的单词
|
|
new_words = [
|
|
{"单词": "cafe", "词性": "n.", "中文释义": "咖啡馆"},
|
|
{"单词": "exhibition", "词性": "n.", "中文释义": "展览"},
|
|
{"单词": "selfie", "词性": "n.", "中文释义": "自拍"},
|
|
{"单词": "typing", "词性": "n.", "中文释义": "打字"},
|
|
{"单词": "performance", "词性": "n.", "中文释义": "表演"}
|
|
]
|
|
|
|
# 把新单词转换为DataFrame
|
|
new_df = pd.DataFrame(new_words)
|
|
|
|
# 合并到原数据
|
|
df_combined = pd.concat([df, new_df], ignore_index=True)
|
|
|
|
# 按单词字母顺序排序(忽略大小写)
|
|
df_sorted = df_combined.sort_values(by='单词', key=lambda x: x.str.lower())
|
|
|
|
# 保存结果
|
|
df_sorted.to_excel(file_path, index=False)
|
|
|
|
print(f"\n添加完成!")
|
|
print(f"添加了 {len(new_words)} 个新单词")
|
|
print(f"更新后总行数: {len(df_sorted)}")
|
|
|
|
print("\n新添加的单词:")
|
|
for word in new_words:
|
|
print(f"{word['单词']} - {word['词性']} - {word['中文释义']}")
|