user12380394
user12380394

Reputation:

Pandas does not show the complete csv file

I am trying to print the entirety of an excel sheet which is 900 rows and 6 columns big. I am trying to use pandas to show it. The problem is that it shows the first few rows and columns, then skips to the last few rows, completely skipping the rest.

Here is my code

import pandas as pd

df = pd.read_csv(r'C:\Users\Downloads\research-and-development-survey-2019-csv.csv',
                 encoding= 'unicode_escape')

print(df)

This is the output after executing:

enter image description here

How do I print the whole csv file? I If it is a matter of being too big to be printed, what other choices do I have? I have tried the chunksize function, but I must be doing it wrong since it does not print the csv file at all.

Upvotes: 1

Views: 1208

Answers (1)

Kuldeep Singh Sidhu
Kuldeep Singh Sidhu

Reputation: 3856

with pd.option_context('display.max_rows', None, 'display.max_columns', None):  
    print(df)

if you are using Jupyter notebook use display(df) instead of print(df)

Context manager is used to temporarily set options.

Here I am saying that display.max_rows and display.max_columns should be None (No limit) by default it is 10 and display.max_columns is 5

DOCS: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.option_context.html

Upvotes: 5

Related Questions