I have a text file having lot of rows with 6 columns in each row but there is a \n after every fourth column as well as every 6th column, something like:
Row 1 ---> 1 2 3 4\n 5 6\n
Row 2 ---> 7 8 9 10\n 11 12\n
I am using the command to create dataframe from the file:
df = pd.read_csv('info.txt', header=None, delimiter=r"\s+", names = cols, lineterminator='\n')
But, pandas read_csv is reading the above data as 4 rows even if I am explicitly providing the names of the 6 columns in names attribute of read_csv:
col1 col2 col3 col4 col5 col6
0 1 2 3 4 NaN NaN
1 5 6 NaN NaN NaN NaN
2 7 8 9 10 NaN NaN
3 11 12 NaN NaN NaN NaN
How can I read the data as :
col1 col2 col3 col4 col5 col6
0 1 2 3 4 5 6
1 7 8 9 10 11 12