0

I used np.genfromtxt to load a txt file.

Below is the code

datasets = np.genfromtxt('X&YTrainingsets1.txt',delimiter="")

It happens that I got an error

ValueError: Some errors were detected !
    Line #1162 (got 5 columns instead of 7)
    Line #1163 (got 2 columns instead of 7)

Error

So I had to look through the txt file and I found this. So how do I solve this problem?. Thanks

1 Answers1

0

I used

import pandas as pd
datasets = pd.read_csv('X&YTrainingsets1.txt',delimiter='\s+',index_col=False,header=None)

for i in range(0,len(datasets)):
  if datasets.iloc[i].isnull().sum() == 2: 
    datasets.loc[i][5],datasets.loc[i][6] = datasets.loc[i+1][0],datasets.loc[i+1][1]
  elif datasets.iloc[i].isnull().sum() == 1:
    datasets.loc[i][6] = datasets.loc[i+1][0]
mate00
  • 2,727
  • 5
  • 26
  • 34