Home > Software design >  Can't store txt file data in Python Dataframe
Can't store txt file data in Python Dataframe

Time:02-24

I am following an article about image caption transformer model in tensor flow python. When I try to run the following code it does not show the data when I use the head function.

file = open(dir_Flickr_text,'r')
text = file.read()
file.close()

datatxt = []
  for line in text.split('\n'):
    col = line.split('\t')
    if len(col) == 1:
     continue
    w = col[0].split("#")
    datatxt.append(w   [col[1].lower()])



data = pd.DataFrame(datatxt,columns["filename","index","caption"])

data = data.reindex(columns =. ['index','filename','caption'])  
data = data[data.filename !='2258277193_586949ec62.jpg.1']
uni_filenames = np.unique(data.filename.values)

data.head()

After running this I see three columns (index, filename , caption) with no data at all. While the real file contains enough data and the in the article they display the data too.

CodePudding user response:

It doesn't show any data because the dataframe is empty, probably because datatext is empty. Try using a print() statement before data=pd.DataFrame(... to see what is going on. It is hard for us to debug without the dataset.

  • Related