Untitled

 avatar
user_3839718
python
a month ago
491 B
2
Indexable
Never
import pandas as pd

file_path = "TCORISEAGLES165Mw.tok"
data = []
with open(file_path, "r") as file:
    for line_number, line in enumerate(file, start=1):
        parts = line.strip().split()
        count = parts[0]
        try:
            word = parts[1]
        except IndexError:
            print(f"Error at line {line_number}: {word}")
            continue
        data.append({"count": count, "word": word})


df = pd.DataFrame(data)
df.to_csv("TCORISEAGLES165Mw.csv", index=False)
Leave a Comment