假设需对“词”这一列去重,可直接挪用以下代码:
import pandas as pd
# 读取Excel文件
file_path = 'test.xlsx'
df = pd.read_excel(file_path)
word_column = '词'
# 对“词”列进行去重
unique_words = df[word_column].unique()
# 创建一个新的DataFrame,只包含去重后的“词”列
new_df = pd.DataFrame(unique_words, columns=[word_column])
# 将去重后的数据保存到新的Excel文件中
output_file_path = 'test.xlsx'
new_df.to_excel(output_file_path, index=False)
print(f"去重后的数据已保存到:{output_file_path}")