How to view a dataframe in Python

Learn how to view a Python DataFrame with our guide. Discover different methods, tips, real-world applications, and how to debug common errors.

How to view a dataframe in Python
Published on: 
Wed
Mar 25, 2026
Updated on: 
Fri
Mar 27, 2026
The Replit Team

The ability to view a pandas DataFrame is a crucial first step in any data analysis workflow. You can inspect data, verify its structure, and check for errors before you proceed.

In this article, you'll learn several techniques to display your data. We'll provide practical tips, real-world applications, and debugging advice to help you effectively inspect your DataFrames.

Basic display of a dataframe

import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
print(df)--OUTPUT--A B
0 1 4
1 2 5
2 3 6

The most direct way to view your DataFrame is by using the print() function. When you pass a DataFrame object to print(), pandas renders a clean, tabular view of your data. This output automatically includes the index on the left and the column headers at the top, giving you an immediate sense of the dataset's structure.

This method is perfect for a quick inspection. For larger DataFrames, pandas intelligently truncates the output, showing only the first and last few rows. This prevents your console from being flooded with data while still giving you a useful snapshot.

Basic dataframe viewing methods

While a simple print() is useful, pandas provides several built-in methods to examine specific parts and summaries of your DataFrame with more control.

Using head() and tail() to view portions

import pandas as pd
df = pd.DataFrame({'A': range(1, 11), 'B': range(11, 21)})
print(df.head(3)) # First 3 rows
print(df.tail(2)) # Last 2 rows--OUTPUT--A B
0 1 11
1 2 12
2 3 13
A B
8 9 19
9 10 20

When you don't need to see the entire DataFrame, the head() and tail() methods are your best friends. They allow you to quickly sample the beginning or end of your data.

  • The head() method returns the first few rows. By default, it shows five, but you can specify a number, like head(3), to see the first three.
  • Similarly, tail() shows you the last rows.

These functions are essential for getting a quick sense of your data's structure and content without overwhelming your screen, especially with large files.

Getting summary statistics with describe()

import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3, 4, 5], 'B': [10, 20, 30, 40, 50]})
print(df.describe())--OUTPUT--A B
count 5.000000 5.000000
mean 3.000000 30.000000
std 1.581139 15.811388
min 1.000000 10.000000
25% 2.000000 20.000000
50% 3.000000 30.000000
75% 4.000000 40.000000
max 5.000000 50.000000

For a high-level statistical summary of your numerical columns, use the describe() method. It instantly computes several key metrics, giving you a solid understanding of your data's distribution and scale.

  • count: The number of non-empty values.
  • mean: The average of all values in the column.
  • std: The standard deviation, which measures data spread.
  • min/max: The minimum and maximum values.

This output is perfect for quickly identifying the range of your data and spotting potential issues like unusually large or small values.

Viewing dataframe information with info()

import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'c'], 'C': [1.1, 2.2, 3.3]})
df.info()--OUTPUT--<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 A 3 non-null int64
1 B 3 non-null object
2 C 3 non-null float64
dtypes: float64(1), int64(1), object(1)
memory usage: 200.0+ bytes

The info() method provides a technical summary of your DataFrame. It’s perfect for quickly assessing your data's structure and integrity, going beyond the statistical summary of describe().

  • Data Types: It reveals the Dtype for each column, so you can verify if numbers are stored correctly (e.g., int64) and text as objects.
  • Missing Values: The “Non-Null Count” for each column makes it easy to spot missing data at a glance.
  • Memory Usage: You also get an estimate of how much memory the DataFrame occupies.

Advanced dataframe viewing techniques

While the basic methods give you the raw facts, you can use advanced techniques to format, plot, and fine-tune the display for much clearer analysis.

Styling dataframes with style attributes

import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
styled_df = df.style.highlight_max(axis=0)
styled_df--OUTPUT--# Note: In a Jupyter notebook, this would display a styled dataframe
# with maximum values highlighted in each column

Pandas' style attribute lets you add conditional formatting to your DataFrame, making it much easier to read. It doesn't change your underlying data; it just returns a Styler object with visual styles applied. For example, the highlight_max() method visually emphasizes the largest value in each column.

  • This is incredibly useful for quickly spotting outliers or key data points.
  • It also helps in creating more engaging reports or presentations.

Keep in mind that these styles are rendered in environments that support HTML, like Jupyter Notebooks.

Visualizing dataframe data with plot()

import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [4, 3, 2, 1]})
df.plot(kind='bar')
plt.show()--OUTPUT--# Note: This would display a bar chart visualization of the dataframe

Sometimes, a picture is worth a thousand rows. The plot() method lets you quickly visualize your data without leaving pandas. It's a convenient wrapper for the popular Matplotlib library, turning your DataFrame into a chart with a single command.

  • You can specify the chart type using the kind parameter, such as kind='bar' for a bar chart.
  • This is perfect for spotting trends, patterns, or relationships that aren't obvious in a table.

Customizing display options with pd.set_option()

import pandas as pd
pd.set_option('display.max_rows', 4)
pd.set_option('display.max_columns', 3)
df = pd.DataFrame({'A': range(10), 'B': range(10, 20), 'C': range(20, 30)})
print(df)--OUTPUT--A B C
0 0 10 20
.. .. .. ..
8 8 18 28
9 9 19 29

[10 rows x 3 columns]

For persistent control over how your DataFrames are displayed, you can use pd.set_option(). This function adjusts pandas' global settings, affecting all DataFrames in your session. It’s perfect for tailoring the output to fit your screen or analysis needs, especially with large datasets.

  • display.max_rows lets you define how many rows are shown before the output is truncated.
  • display.max_columns does the same for columns.

This gives you full authority over what you see, preventing your console from being flooded with data.

Move faster with Replit

Replit is an AI-powered development platform that transforms natural language into working applications. Describe what you want to build, and Replit Agent creates it—complete with databases, APIs, and deployment.

For the DataFrame viewing techniques we've explored, Replit Agent can turn them into production tools:

  • Build a data profiler that ingests a file and automatically displays key summaries using info() and describe().
  • Create a live data dashboard that periodically fetches data and shows the latest entries with tail().
  • Deploy a data validation tool that uses describe() to flag outliers and info() to check for missing values before processing.

Describe your app idea, and Replit Agent writes the code, tests it, and fixes issues automatically, all in your browser.

Common errors and challenges

While viewing DataFrames is usually straightforward, you might encounter a few common display quirks that can be easily resolved.

Calculations involving missing data often result in NaN (Not a Number) values, which can make your output confusing. When a mathematical operation meets a NaN, the result is another NaN, which can quickly spread across your dataset.

  • To prevent this, you can handle missing values before your calculations. Use the fillna() method to replace NaN with a specific value, like zero.
  • Alternatively, if the rows or columns with missing data aren't critical, you can remove them entirely using dropna().

If your DataFrame has many columns, pandas will often hide the ones in the middle, replacing them with an ellipsis (...). While this keeps your display tidy, it can be a problem when you need to see every single column at once.

You can override this default behavior by setting pd.set_option('display.max_columns', None). This tells pandas to show all columns, no matter how many there are. You can always reset it later if your screen gets too cluttered.

Sometimes, floating-point numbers show up with a long trail of decimal places, making your DataFrame look messy and hard to interpret. You don't always need that level of precision for a quick analysis.

  • A simple fix is to adjust a global setting with pd.set_option('display.precision', 2), which would round all floats to two decimal places in the display.
  • For more targeted changes, you can use the style.format() method on a specific DataFrame. This lets you apply formatting—like controlling decimal places—to certain columns without affecting any other output.

Handling NaN display issues when calculating with DataFrames

When you perform calculations like finding the percentage change with pct_change(), pandas can introduce new NaN values. This happens because the first row has no previous value to compare against, and any calculation involving an existing NaN also results in NaN.

The code below demonstrates how these NaN values appear when calculating the percent change in a column that already contains missing data.

import pandas as pd
import numpy as np

# Create DataFrame with missing values
df = pd.DataFrame({
'A': [1, 2, np.nan, 4],
'B': [5, np.nan, 7, 8]
})

# Attempt to calculate percent change (will show NaN values)
df['Pct_Change'] = df['A'].pct_change() * 100
print(df)

The pct_change() function creates a NaN in the first row because there's no prior value for comparison. It also propagates existing NaNs, as seen in the third row. The code below demonstrates how to manage these values effectively.

import pandas as pd
import numpy as np

# Create DataFrame with missing values
df = pd.DataFrame({
'A': [1, 2, np.nan, 4],
'B': [5, np.nan, 7, 8]
})

# Fill NaN values before calculating percent change
df['A_filled'] = df['A'].fillna(method='ffill')
df['Pct_Change'] = df['A_filled'].pct_change() * 100
print(df)

To avoid calculation errors, you can manage missing data first. The solution uses fillna(method='ffill') to create a new, clean column.

  • This "forward fill" method replaces each NaN with the last valid observation, which is useful for ordered data.

With the gaps filled, running pct_change() on the new column works as expected, preventing the spread of NaN values and keeping your calculations accurate.

Resolving truncated output with wide DataFrames

It’s a common scenario: you create or load a wide DataFrame, and pandas helpfully hides the middle columns to save space. While well-intentioned, this truncation can prevent you from getting a full view. The following code shows exactly what this looks like.

import pandas as pd
import numpy as np

# Create a wide DataFrame with many columns
wide_df = pd.DataFrame(np.random.rand(5, 20))

# This will truncate columns in the middle
print(wide_df)

The DataFrame's 20 columns exceed pandas' default display limit, causing the middle columns to be hidden. The following code shows how to override this behavior and force all columns to appear in the output.

import pandas as pd
import numpy as np

# Create a wide DataFrame with many columns
wide_df = pd.DataFrame(np.random.rand(5, 20))

# Show all columns without truncation
pd.set_option('display.max_columns', None)
print(wide_df)

By setting pd.set_option('display.max_columns', None), you instruct pandas to show all columns, overriding the default truncation. This global change ensures you see the entire width of your DataFrame, which is essential for tasks like data validation or comparing features side-by-side. Keep this setting in mind whenever you're working with datasets that have more columns than your screen can initially show, as it gives you a complete, uninterrupted view of your data.

Fixing display issues with floating-point precision

When you're working with floats, you'll notice pandas defaults to high precision. This can lead to cluttered tables filled with long decimal trails, which isn't always ideal for readability. The following code shows what this default formatting looks like in practice.

import pandas as pd

# Create DataFrame with floating-point values
float_df = pd.DataFrame({
'Value': [0.12345678, 1.23456789, 12.3456789],
'Ratio': [0.987654321, 0.876543210, 0.765432109]
})

# Default display shows too many decimal places
print(float_df)

The code creates a DataFrame with standard floats, but pandas' default display settings make them hard to read by showing excessive decimal places. The following code demonstrates how to format the output for better readability.

import pandas as pd

# Create DataFrame with floating-point values
float_df = pd.DataFrame({
'Value': [0.12345678, 1.23456789, 12.3456789],
'Ratio': [0.987654321, 0.876543210, 0.765432109]
})

# Set floating-point precision for display
pd.set_option('display.float_format', '{:.3f}'.format)
print(float_df)

To clean up those long, messy decimal numbers, you can set a global display rule. The solution uses pd.set_option('display.float_format', '{:.3f}'.format) to format all floating-point numbers to show just three decimal places.

  • This change affects every DataFrame in your current session, making all your outputs instantly cleaner.
  • It's perfect for creating readable reports or when high precision isn't necessary for your analysis.

Real-world applications

With display issues managed, you can apply these methods to tasks like formatting financial data with set_index() and analyzing correlations with corr().

Formatting financial data with set_index()

For financial data, setting a meaningful column like 'Quarter' as the index with set_index() makes your DataFrame cleaner and more aligned with standard reporting formats.

import pandas as pd

# Create financial data for quarterly report
financials = pd.DataFrame({
'Quarter': ['Q1', 'Q2', 'Q3', 'Q4'],
'Revenue': [12500, 15000, 16700, 18900],
'Expenses': [11000, 14000, 15200, 16500]
})

# Calculate profit and set index
financials['Profit'] = financials['Revenue'] - financials['Expenses']
financials = financials.set_index('Quarter')

print(financials)

This code builds a financials DataFrame and then creates a new Profit column using a vectorized operation—subtracting the Expenses column from the Revenue column for all rows simultaneously. The final step uses set_index('Quarter') to replace the default numeric index with the more meaningful quarter labels.

  • This change makes data access more intuitive. You can now select rows using labels like 'Q1' instead of relying on their numerical position.

Analyzing correlations with the corr() method

The corr() method simplifies relationship analysis by computing a correlation matrix, which shows how strongly and in what direction your numerical columns are linked.

import pandas as pd

# Create dataset with different correlation patterns
data = pd.DataFrame({
'A': [10, 20, 30, 40, 50],
'B': [12, 22, 31, 43, 55], # Highly correlated with A
'C': [50, 40, 30, 20, 10] # Negatively correlated with A
})

# Calculate and display correlation matrix
correlation = data.corr().round(2)
print(correlation)

This code creates a DataFrame and then uses the corr() method to compute the pairwise correlation of its columns. The resulting matrix quantifies the linear relationship between each pair of columns, with values ranging from -1 to 1.

  • A value near 1.0, like between columns A and B, suggests they move in the same direction.
  • A value near -1.0, as seen between A and C, indicates they move in opposite directions.

Finally, round(2) is used to make the output easier to read.

Get started with Replit

Turn these techniques into a real tool. Tell Replit Agent to “build a CSV analyzer that shows summary stats and missing values” or “create a dashboard that displays a correlation matrix from a stock data file.”

The agent writes the code, tests for errors, and deploys your app. Start building with Replit and bring your data tools to life.

Get started free

Create and deploy websites, automations, internal tools, data pipelines and more in any programming language without setup, downloads or extra tools. All in a single cloud workspace with AI built in.

Get started for free

Create & deploy websites, automations, internal tools, data pipelines and more in any programming language without setup, downloads or extra tools. All in a single cloud workspace with AI built in.