How to print very long string completely in pandas DataFrame?

Given a Pandas DataFrame, we have to print very long string completely.
Submitted by Pranit Sharma, on June 17, 2022

Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and the data.

A string in pandas can also be converted into pandas DataFrame with the help StringIO method.

A string is a group of characters. A string can contains any type of character including numerical characters, alphabetical characters, special characters, etc.

To print very long strings completely in panda DataFrame, we will use pd.options.display.max_colwidth() method.

To work with pandas, we need to import pandas package first, below is the syntax:

import pandas as pd

Let us understand with the help of an example,

Python code to print very long string completely in pandas DataFrame

# Importing pandas package
import pandas as pd

# Creating a dictionary
d= {
    'Column':[1,2,3,4,5,'Welcome to IncludeHelp, You are learning how to print a long string.']

# Creating a DataFrame
df = pd.DataFrame(d)

# Display DataFrame
print("Created DataFrame\n",df,"\n")


Example 1: Print very long string

Here, we can observe that the string in the column is not printed completely, hence we will use pd.options.display.max_colwidth() to display the entire string.

# Setting limit for string
pd.options.display.max_colwidth = 100

# Display df again
print("Entire String:\n",df)


Example 2: Print very long string

Python Pandas Programs »


Comments and Discussions!


Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.