将文本文档转换为包含三列的电子表格：单词、出现次数和频率。
import pandas as pd 

# 读取文件 
with open('file.txt', 'r') as f: 
    words = f.read().split() 

# 创建数据帧 
words_df = pd.DataFrame(words, columns=['word']) 

# 统计每个单词的出现次数 
words_df['number of occurrences'] = words_df.groupby('word').transform('count') 

# 计算每个单词的频率 
words_df['frequency'] = words_df['number of occurrences']/len(words) 

# 打印数据帧 
print(words_df)