Convert text to csv

Hi I have a promblem with my code that convert txt to csv.

Here is my code

import os
from os import listdir
from os.path import isfile, join
import numpy as np
import pandas as pd

def find_file():
onlyfiles = [f for f in listdir(os.getcwd() + ‘/mit_data’) if isfile(join(os.getcwd() + ‘/mit_data’, f))]
return np.unique([file[0:3] for file in onlyfiles])[1:].tolist()

file_num = find_file()

for i in range(0, 46):
read_file = pd.read_csv(‘C:\Users\jay\Desktop\mit\mit_data\100annotations.txt’.format(file_num[i]), header=None, delimiter = ‘\t’)
read_file.to_csv(‘C:\Users\jay\Desktop\mit\converted csv data\100annotations.csv’.format(file_num[i]), index=None)

And plus Is there a way to connect the sample# to the row in txt file and csv file if the sample# matches and merge them to one csv file? I attach a picture that I want to do.

1 Like

Switching to Programming Help for better visibility.