-1

I have tried reading a text file in python using the following lines of code:

import re
import pandas as pd

book = open('C:/Users/anankrit/Downloads/output.txt',encoding="utf-8")
booktxt = book.readlines()
book.close()
#to remove /n
for index, line in enumerate(booktxt):
      booktxt[index] = line.strip()
booktxt[0:2]

O/p: ['dbi_snapshot_day\tmarketplace_id\twarehouse_id\tdisposition,'2022-04-16\t1\tATL2\tSELLABLE']

My problem statement is everything is there in the same column,the delimiter is \t. how can i split it into different columns which are:dbi_snapshot_day,marketplace_id,warehouse_id,disposition

  • Why do you expect to have miltiple columns? Where do you split the lines you read? There's no point reinventing the wheel -- [parsing a tab-separated file in Python](https://stackoverflow.com/questions/11059390/parsing-a-tab-separated-file-in-python) – Pranav Hosangadi May 16 '22 at 20:02

0 Answers0