To print a full dataframe in Python, you can use the pd.set_option() function from the Pandas library to set the maximum number of columns and rows to be displayed. Here’s an example:
import pandas as pd # create a sample dataframe df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}) # set display options to show all columns and rows pd.set_option('display.max_columns', None) pd.set_option('display.max_rows', None) # print the dataframe print(df)
This will print the entire dataframe to the console, without any truncation of columns or rows. Note that if the dataframe is very large, printing the full dataframe may not be practical or readable, and it may be better to only print a subset of the data.
Another example would be:
import pandas as pd import numpy as np # create a sample dataframe with 10 rows and 10 columns df = pd.DataFrame(np.random.randn(10, 10)) # set display options to show all columns and rows pd.set_option('display.max_columns', None) pd.set_option('display.max_rows', None) # print the dataframe print(df)
This code will create a dataframe with 10 rows and 10 columns of random data using the NumPy library. Then, it sets the display options to show all columns and rows, and finally prints the full dataframe to the console.
Note that when setting the max_columns and max_rows options to None, the entire dataframe will be displayed, regardless of its size. This may not be practical or efficient for very large dataframes, so it’s often a good idea to only display a subset of the data or to use other methods for data exploration and visualization.