5/31/2023 0 Comments Python convert txt to csv![]() ![]() I don't want spaces and need for the Issue ID column to only have the ID=u'number' data and the Name of issue to only have the POP Issue data. This is what this code outputs - which is close but not quite right. Writer.writerow(('Name of Issue', 'Issue ID')) With open('newfile1.csv', 'w') as out_file: Lines = (line for line in stripped if line) Stripped = (line.strip() for line in in_file) After successful run of above code, a file named GeeksforGeeks.csv will be created in the same directory. With open('newfile1.txt', 'r') as in_file: dataframe1 pd.readcsv ('GeeksforGeeks.txt') dataframe1.tocsv ('GeeksforGeeks.csv', index None) Output: CSV File formed from given text file The text file read is same as above. The following code has worked to get the column names at the top of my CSV as well as splitting, but it is not in the right format and doesn't separate by ", ". The goal is to throw this into a CSV file that looks like the following with 2 columns: Name of issueīasically using the ", " in the txt file to act as a delimiter and separate the two into columns. My text document is in the following format: POP Issue: key=u'VPER-242', id=u'167782' I've been trying to convert a txt file to CSV but have been running into trouble.
0 Comments
Leave a Reply. |