Load data from txt with pandas
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Industries in Orbit Looping
--
Chapters
00:00 Question
00:58 Accepted answer (Score 70)
01:20 Answer 2 (Score 339)
01:45 Answer 3 (Score 142)
02:03 Answer 4 (Score 52)
02:26 Thank you
--
Full question
https://stackoverflow.com/questions/2154...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #io #pandas
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Industries in Orbit Looping
--
Chapters
00:00 Question
00:58 Accepted answer (Score 70)
01:20 Answer 2 (Score 339)
01:45 Answer 3 (Score 142)
02:03 Answer 4 (Score 52)
02:26 Thank you
--
Full question
https://stackoverflow.com/questions/2154...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #io #pandas
#avk47
ANSWER 1
Score 359
You can use:
data = pd.read_csv('output_list.txt', sep=" ", header=None)
data.columns = ["a", "b", "c", "etc."]
Add sep=" " in your code, leaving a blank space between the quotes. So pandas can detect spaces between values and sort in columns. Data columns is for naming your columns.
ANSWER 2
Score 156
I'd like to add to the above answers, you could directly use
df = pd.read_fwf('output_list.txt')
fwf stands for fixed width formatted lines.
ANSWER 3
Score 55
@Pietrovismara's solution is correct but I'd just like to add: rather than having a separate line to add column names, it's possible to do this from pd.read_csv.
df = pd.read_csv('output_list.txt', sep=" ", header=None, names=["a", "b", "c"])
ANSWER 4
Score 34
you can use this
import pandas as pd
dataset=pd.read_csv("filepath.txt",delimiter="\t")