I am a newbie when it comes to Python/Pandas.
I am able to upload successfully a text.txt file into Python with the following query.
For x no. of spaces, use regex:
import re
x = []
with open('U:\\text.txt') as file:
for i in file:
z = re.split('\s ', i)
y = []
for i in z:
if i.endswith('\n'): y.append(i[:-1])
else: y.append(i)
x.append(y)
import pandas as pd
cols = list('Cols' str(i) for i in range(1, 10)) # Generates [Cols1, Cols2, .. ,Cols18, Cols19]
df = pd.DataFrame(x, columns = cols)
df.head()
Peace!
CodePudding user response:
As I understood it correctly, you are using different deliminter among your txt file. You shoud set it as a space or a tab. Not both. Make it all the same and you might be good.