user7759009
user7759009

Reputation:

Reading an excel file in pandas

I am reading an excel file into pandas, but I am getting the following:

Out[8]:
0        \tFLOOD LIGHTS\t
1        \tFLOOD LIGHTS\t
2        \tPAR 38 LIGHT\t
3                \tMILO\t
4    \tQ-12251-DO1 MILO\t

I do not want the "\t" in my data. Here is my pandas read command:

import pandas as pd
data = pd.read_ex('/home/Desktop/sample.xlsx')

Upvotes: 3

Views: 328

Answers (1)

jezrael
jezrael

Reputation: 862396

It seems you have trailing tabs in your data.

So need strip for remove it:

data['col'] = data['col'].str.strip()

If all columns:

data = data.apply(lambda x: x.str.strip())

#then convert possible numeric columns
data['num_col'] = data['num_col'].astype(int)

Or if need remove \t strings use replace with ^ for start of string and $ for end:

data = data['col'].replace(['^\t', '\t$'], '', regex=True)

Upvotes: 2

Related Questions