Miyn
Miyn

Reputation: 1

Load data from txt with pandas, columns seperated by ;

I am trying to load a txt file containig a mix of various data. It also contains empty fields

import pandas as pd

data = pd.read_csv('data.txt', header = None)

Structure of my input file:

column1;column2;column3;column4;column5;column6;column7;column8;column9;column10;column11
2011110602563790001;4445; ;B;-70.111;-2.630;0;1.7;2.4;1.1;3.555

Column3 mostly has no content

I tried to load the data in various ways but it doesn't seem to work with this txt. How can I load the text file with python? Any help is appreciated.

Upvotes: 0

Views: 47

Answers (2)

Thomas Vivier
Thomas Vivier

Reputation: 60

You just forgot to precise the sep (find all parameters here : https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html)

Here is the code :

import pandas as pd

data = pd.read_csv('data.txt', header = None, sep =';')

Upvotes: 2

Andre S.
Andre S.

Reputation: 518

Try to define the delimiter:

pd.read_csv('data.txt', header = None, sep=";")

Upvotes: 1

Related Questions