banana_99
banana_99

Reputation: 641

Pandas excel import truncating long string

I have an excel file with the below cell content

\\pathxx01\xxx project\71 XXXX XXXXXXX Team\Landlord Billing/

However, when importing the excel into a pandas dataframe with pd.read_excel method, the string is truncated to

\\pathxx01\xxx project\71 XXXX XXXXXXX Team\Lan...

Is there any way to avoid this truncation and keep the original string?

Upvotes: 4

Views: 1651

Answers (2)

user17242583
user17242583

Reputation:

As determined from the comments, it's not actually being truncated. Pandas is just displaying it truncated because there is little screenspace where you're displaying it.

You can use this to force Pandas to display the full columns without truncating them:

pd.set_option('display.max_colwidth', None)

Upvotes: 4

Lorenzo Bassetti
Lorenzo Bassetti

Reputation: 945

I solved similar issues using xlwings library, very handy for reasing single cell values to a variable, numpy arrays and pandas dataframes.

A quick sample:

import xlwings as xw
import numpy as np
import pandas as pd

worksheet = xw.Book(file_path).sheets['Sheet1']
myCellValue= xw.Book(file_path).sheets['Sheet1'].range('M4').value
myArray= np.array(worksheet.range("A1:A100").value)

imho this works more solidly than other solutions.

Upvotes: 0

Related Questions