import pandas as pd 

# Read file 
with open('file.txt', 'r') as f: 
    words = f.read().split() 

# Create dataframe 
words_df = pd.DataFrame(words, columns=['word']) 

# Count the occurrences of each word 
words_df['number of occurrences'] = words_df.groupby('word').transform('count') 

# Calculate the frequency of each word 
words_df['frequency'] = words_df['number of occurrences']/len(words) 

# Print the dataframe 
print(words_df)
Converti il documento di testo in un foglio di calcolo che contiene tre colonne: parola, numero di occorrenze e frequenza.