lassence.net

Field notes from the AI frontier

Display more DataFrame cells in Jupyter notebooks

--- archive: codebook, 2020–2023 · topic: Pandas ---

By default, when printing a pandas DataFrame, Jupyter notebooks display a maximum of 60 rows and 20 columns. Beyond these limits, it will only display the first and last values.

Also, there is a default column width, and values will be cropped if they exceed this width.

# Import libraries
import pandas as pd
import numpy as np

# Show current display option
print("Max rows:", pd.get_option("display.max_rows"))
print("Max columns:", pd.get_option("display.max_columns"))
print("Max column width:", pd.get_option("display.max_colwidth"))
Max rows: 60
Max columns: 20
Max column width: 50

Change the columns maximum width

# DataFrame with looong values
hamlet = [["To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer"],
          ["The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles,"],
          ["And by opposing end them? To die: to sleep; No more; and by a sleep to say we end"],
          ["The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation"],
          ["Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub;"],
          ["For in that sleep of death what dreams may come When we have shuffled off this mortal coil,"],
          ["Must give us pause: there's the respect That makes calamity of so long life;"]]
df = pd.DataFrame(hamlet)
df
0
0To be, or not to be: that is the question: Whe…
1The slings and arrows of outrageous fortune, O…
2And by opposing end them? To die: to sleep; No…
3The heart-ache and the thousand natural shocks…
4Devoutly to be wish’d. To die, to sleep; To sl…
5For in that sleep of death what dreams may com…
6Must give us pause: there’s the respect That m…
# Change max columns width to 100 characters
pd.set_option("display.max_colwidth", 100)
df
0
0To be, or not to be: that is the question: Whether ’tis nobler in the mind to suffer
1The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles,
2And by opposing end them? To die: to sleep; No more; and by a sleep to say we end
3The heart-ache and the thousand natural shocks That flesh is heir to, ’tis a consummation
4Devoutly to be wish’d. To die, to sleep; To sleep: perchance to dream: ay, there’s the rub;
5For in that sleep of death what dreams may come When we have shuffled off this mortal coil,
6Must give us pause: there’s the respect That makes calamity of so long life;

Change the number of rows and columns displayed

# Create a DataFrame with 100 rows and 30 columns
df = pd.DataFrame(np.random.random(3000).round(2).reshape(100, 30))
df
0123456789…20212223242526272829
00.280.290.730.301.000.470.890.130.760.28…0.110.970.550.370.710.560.730.960.940.71
10.620.430.700.390.540.910.040.230.680.40…0.860.950.860.840.260.840.330.620.080.86
20.520.390.740.500.480.830.410.230.590.25…0.800.510.740.590.480.530.060.310.700.73
30.100.820.820.110.790.240.180.610.920.65…0.630.230.890.100.840.680.170.470.420.18
40.360.510.500.340.660.500.570.170.300.64…0.930.040.970.530.910.820.460.810.730.98
…………………………………………………………
950.090.740.530.460.700.850.320.300.110.64…0.760.900.240.360.840.120.390.250.150.80
960.220.100.460.930.790.470.210.460.980.29…0.740.400.790.070.140.260.720.790.870.68
970.230.090.870.360.440.050.050.240.930.25…0.460.430.690.160.660.300.520.180.590.17
980.670.240.190.330.240.050.460.360.220.47…0.960.100.650.350.620.020.300.590.750.81
990.090.730.500.190.080.700.700.620.970.59…0.850.880.700.790.910.860.130.990.100.05

To change the number of DataFrame rows and columns displayed at the same time in the Jupyter notebook, use pd.set_option().
For more options, refer to the pandas documentation.

# Change display options
pd.set_option("display.max_rows", 100)
pd.set_option("display.max_columns", 50)
df
01234567891011121314151617181920212223242526272829
00.280.290.730.301.000.470.890.130.760.280.030.570.640.900.280.110.310.740.010.140.110.970.550.370.710.560.730.960.940.71
10.620.430.700.390.540.910.040.230.680.400.020.220.950.780.110.840.660.480.840.960.860.950.860.840.260.840.330.620.080.86
20.520.390.740.500.480.830.410.230.590.250.860.640.630.400.510.300.990.130.130.480.800.510.740.590.480.530.060.310.700.73
30.100.820.820.110.790.240.180.610.920.650.470.320.100.810.110.390.070.300.130.170.630.230.890.100.840.680.170.470.420.18
40.360.510.500.340.660.500.570.170.300.640.100.670.320.170.110.450.700.090.620.490.930.040.970.530.910.820.460.810.730.98
50.300.820.290.730.790.860.120.590.900.100.790.120.670.890.440.760.170.420.940.810.040.240.820.040.050.880.670.760.350.71
60.800.070.540.390.010.680.670.760.120.360.990.820.250.650.810.180.460.710.250.930.820.770.640.030.070.620.360.960.900.94
70.800.190.990.070.050.620.900.030.970.400.170.450.380.820.570.760.780.740.050.300.750.660.860.930.560.640.870.850.830.91
80.510.420.340.820.610.140.570.220.090.410.120.570.710.020.440.400.360.070.000.090.730.980.910.670.320.000.320.940.130.94
90.730.030.840.900.870.370.760.820.590.670.250.260.560.280.670.460.130.020.370.610.830.700.330.930.340.200.340.960.470.98
100.820.380.420.460.600.110.530.540.980.400.750.480.720.460.490.700.320.280.930.850.850.930.540.400.940.210.970.020.630.50
110.400.980.120.300.780.800.920.200.960.510.550.980.880.240.380.630.520.990.430.020.150.500.010.230.340.150.510.090.860.77
120.190.170.080.880.390.980.860.260.370.130.960.540.310.920.590.760.430.000.490.900.020.250.250.880.640.500.460.510.340.85
130.310.520.470.320.090.810.580.470.700.960.850.560.400.980.360.960.710.080.740.430.680.380.690.710.260.420.880.350.940.37
140.090.120.550.820.170.420.520.480.800.480.840.540.500.760.930.680.270.310.820.710.010.070.680.570.690.950.980.730.840.51
150.990.400.420.420.270.870.150.500.500.150.130.540.160.540.600.080.540.490.840.560.120.860.400.590.530.960.200.540.150.45
160.490.670.470.250.170.010.591.000.960.640.700.160.050.980.260.260.760.900.550.450.910.640.380.790.650.960.490.250.810.74
170.820.720.590.400.440.610.400.650.700.020.800.560.160.620.310.880.841.000.490.950.290.490.930.170.600.930.380.250.970.78
180.130.050.490.530.970.880.970.410.630.480.220.120.460.990.300.390.320.920.720.110.330.730.470.560.980.100.960.650.881.00
190.840.930.960.970.620.480.130.420.810.500.390.660.990.620.200.970.850.510.510.580.470.060.060.800.540.180.710.350.370.48
200.590.200.680.440.330.820.850.220.520.850.490.630.000.510.020.890.150.770.060.500.600.320.660.630.660.450.510.520.280.75
210.450.260.340.830.840.660.460.050.070.730.510.220.060.800.620.450.260.460.360.280.300.410.600.610.080.150.690.670.250.29
220.520.800.970.120.390.580.940.960.120.330.850.560.020.630.460.870.050.900.580.340.590.670.450.890.370.080.860.070.980.33
230.410.180.190.390.300.730.270.080.880.820.410.090.880.790.270.980.790.950.550.070.220.470.920.320.860.950.440.840.100.36
240.140.860.260.590.500.040.100.760.520.850.840.580.200.370.790.950.110.210.630.190.270.051.000.810.670.310.980.950.960.37
250.350.060.560.830.330.250.580.660.410.080.830.970.720.980.560.880.510.280.280.900.780.660.870.760.790.340.310.770.470.47
260.240.480.850.180.300.790.520.270.570.950.640.580.490.860.430.770.510.110.580.950.290.980.420.360.890.010.270.980.150.27
270.990.910.000.140.270.900.020.710.240.170.480.240.610.350.700.220.420.030.410.530.400.620.970.860.920.940.560.650.300.26
280.360.830.210.630.500.830.490.810.550.820.290.620.430.690.430.380.410.620.120.990.730.660.330.110.470.350.140.050.230.96
290.610.550.020.750.180.471.000.330.130.250.420.630.160.020.010.070.350.190.400.110.200.750.810.980.750.520.500.320.130.12
300.250.480.110.150.220.120.170.550.400.990.920.790.770.540.730.580.530.800.260.510.130.700.210.090.850.960.610.070.250.81
310.100.750.000.750.380.230.500.850.720.940.180.080.260.670.290.800.220.690.250.870.850.130.990.640.900.410.130.780.120.76
320.270.930.940.610.680.100.920.100.780.860.950.140.330.360.800.670.930.430.240.960.060.630.870.700.760.440.900.550.320.59
330.680.650.440.780.970.550.800.200.120.660.660.530.290.930.770.770.510.340.640.540.280.740.760.780.770.020.910.800.730.32
340.610.370.200.140.470.770.370.980.530.090.780.440.480.230.130.410.080.810.850.520.310.590.240.870.300.290.300.830.320.00
350.810.620.530.240.690.380.530.880.950.470.510.490.860.600.540.690.460.540.271.000.220.280.780.880.380.830.320.350.800.73
360.620.020.740.750.230.100.950.800.880.770.960.160.990.190.380.170.270.190.630.960.630.580.970.550.300.120.870.590.130.19
370.640.770.420.120.540.800.470.200.760.360.910.380.580.370.730.680.450.750.390.650.590.370.750.040.550.360.080.260.350.66
380.790.120.460.580.870.430.050.850.200.450.560.890.580.290.200.990.720.800.250.860.400.270.750.530.430.500.950.570.370.27
390.080.580.500.440.530.290.210.300.790.510.470.440.040.950.620.750.580.650.890.350.610.080.300.520.340.770.770.420.240.84
400.150.240.340.400.700.240.550.610.740.720.860.030.840.580.090.870.990.150.860.730.800.150.010.140.860.060.030.900.050.16
410.270.300.670.440.110.840.200.300.310.470.750.720.340.330.980.750.890.290.770.140.980.160.180.140.170.840.210.300.180.44
420.900.830.420.730.280.300.580.810.520.140.340.670.980.470.740.430.000.690.530.100.820.090.030.790.910.470.530.770.810.89
430.430.980.630.370.440.160.180.750.970.490.331.000.670.920.240.010.290.570.360.610.200.140.860.310.760.440.240.430.190.60
440.310.660.290.070.520.440.850.880.590.820.210.380.490.990.810.140.210.250.450.040.470.290.480.160.960.160.640.230.440.12
450.800.470.170.500.090.690.970.800.760.420.780.450.030.690.830.510.050.460.960.600.520.430.390.670.910.710.110.570.970.91
460.271.000.350.360.820.500.190.860.090.540.830.920.920.470.510.230.750.800.520.540.500.420.300.890.920.970.990.500.800.99
470.920.030.410.820.890.640.770.150.600.930.560.380.390.160.110.410.770.390.530.020.810.041.000.650.700.060.260.800.270.59
480.110.920.660.800.200.940.450.790.380.920.370.320.860.950.040.950.490.270.600.890.770.510.390.710.530.220.290.280.980.34
490.110.200.080.350.490.990.600.390.470.660.060.980.970.600.050.350.040.520.170.190.540.950.650.350.240.890.060.740.400.63
500.520.890.620.130.400.630.210.350.760.110.240.370.310.690.270.000.770.860.170.740.680.190.150.030.480.820.590.810.690.94
510.490.430.100.220.490.060.540.870.080.910.330.280.520.110.410.880.610.940.750.520.680.780.750.520.010.340.530.400.670.85
520.870.210.990.850.030.340.190.190.970.930.630.420.200.140.540.710.370.460.140.350.920.460.680.180.230.070.390.870.410.33
530.600.640.140.350.520.990.550.200.370.090.700.380.560.630.230.920.880.140.820.880.310.500.010.120.110.580.930.140.500.18
540.430.100.360.320.420.080.140.850.360.930.610.320.180.260.580.780.980.170.140.080.060.670.240.380.550.361.000.550.520.51
550.990.420.210.690.860.680.520.400.030.510.960.650.630.690.970.750.340.130.750.260.170.660.660.750.790.970.990.730.810.95
560.800.270.170.380.650.670.480.020.570.100.560.700.050.151.000.290.970.380.300.170.760.440.080.820.280.050.620.770.560.34
570.240.650.250.380.420.140.800.760.570.450.210.020.350.600.590.230.380.990.680.340.360.900.231.000.660.770.160.300.680.24
580.380.290.550.070.940.090.870.370.760.550.550.290.200.890.400.240.700.710.830.430.300.470.800.430.960.790.760.100.820.23
590.250.990.590.500.140.740.770.670.410.020.280.220.850.040.590.470.670.480.670.260.490.080.440.320.110.610.890.670.020.60
600.860.920.661.000.920.230.030.940.450.890.620.750.090.640.470.640.880.350.490.290.790.560.600.770.030.330.020.880.290.55
610.990.420.760.950.100.030.800.060.750.610.470.800.190.070.470.510.750.640.890.790.290.260.000.790.360.810.290.220.480.26
620.250.480.300.420.030.570.600.700.400.050.570.130.380.240.470.620.470.680.320.460.070.280.280.300.360.480.680.550.200.03
630.160.190.320.420.430.900.640.430.040.560.290.100.010.020.110.390.180.220.880.930.590.940.340.890.210.110.270.200.310.22
640.730.310.410.740.770.550.780.080.170.490.940.460.350.930.920.690.750.810.610.900.710.480.340.140.270.400.250.430.830.07
650.910.050.510.270.290.490.410.890.460.641.000.950.100.990.210.540.500.400.980.470.960.950.400.070.810.310.200.480.360.71
660.510.590.020.150.840.320.720.660.470.300.190.360.970.630.370.050.920.980.360.050.850.250.360.700.210.120.830.540.090.30
670.360.900.511.000.520.640.170.240.070.530.480.520.090.810.380.080.090.320.090.910.230.550.590.540.390.020.050.490.290.63
680.200.690.620.060.180.430.970.770.460.160.790.410.170.910.010.580.800.750.000.300.710.210.340.250.760.830.110.130.230.46
690.200.350.880.240.970.130.060.790.730.380.640.920.690.830.150.210.020.750.910.830.940.670.230.770.550.900.340.200.730.37
700.450.710.900.640.130.080.100.590.600.350.700.270.780.980.500.120.870.310.930.310.990.200.880.960.320.850.400.880.010.75
710.960.400.330.860.240.570.980.040.920.960.090.890.110.720.580.950.420.840.840.830.790.890.820.400.780.120.850.320.800.84
720.680.630.880.760.600.580.321.000.080.870.530.150.430.470.950.090.170.640.580.540.400.160.121.000.650.680.860.350.640.02
730.420.010.530.100.530.610.660.670.240.430.980.650.250.290.670.610.620.810.960.220.700.220.150.730.100.680.210.200.370.14
740.520.190.220.250.640.860.950.660.840.880.780.250.960.871.000.540.300.040.740.330.320.830.230.610.890.130.520.990.050.16
750.780.470.170.030.320.450.040.760.500.760.710.760.930.850.170.460.410.420.150.620.940.230.720.540.980.340.910.950.350.41
760.960.440.540.960.900.930.960.950.110.260.110.690.920.850.160.740.850.460.070.920.090.350.660.810.610.290.700.560.090.53
770.500.160.030.150.010.070.640.070.960.140.840.700.800.220.870.660.710.470.160.170.450.780.540.400.470.770.430.050.340.14
780.880.030.430.470.150.100.380.490.290.050.050.980.580.350.770.490.730.220.710.610.850.810.060.510.560.660.930.090.700.72
790.050.630.830.130.900.370.100.330.200.730.970.730.730.910.250.950.320.680.080.930.140.440.510.230.680.350.510.160.980.07
800.530.660.020.420.600.240.780.820.630.570.450.610.840.950.610.290.900.990.850.650.470.220.910.710.410.270.980.080.660.44
810.860.020.280.850.500.900.630.880.820.110.980.000.050.850.040.630.670.850.680.750.200.610.250.930.900.010.030.590.680.95
820.960.880.320.570.240.910.450.990.490.010.710.700.450.680.280.510.730.390.460.960.390.560.250.300.960.000.510.180.790.89
830.420.090.990.900.660.570.810.520.110.720.020.490.180.310.540.100.600.910.240.950.290.400.090.770.540.760.130.600.370.46
840.090.330.770.920.250.130.140.670.440.620.610.730.700.520.490.030.450.050.260.990.420.070.830.510.140.500.590.180.990.32
850.530.240.710.170.150.640.650.220.020.990.710.890.780.750.220.630.980.720.250.650.370.140.750.240.230.670.590.270.170.29
860.950.090.450.330.750.600.980.950.790.100.570.060.700.440.720.270.090.770.280.660.190.120.140.860.880.860.840.650.670.73
870.010.900.170.320.100.300.030.070.930.400.810.750.600.240.570.870.670.980.270.600.940.920.800.180.440.040.240.640.070.46
880.650.290.740.280.780.100.440.660.010.410.430.200.090.750.670.970.910.390.460.520.170.290.480.350.850.100.780.530.300.09
890.740.660.580.370.120.530.060.720.910.350.380.010.690.120.390.510.910.430.550.770.120.640.730.250.090.750.690.560.890.77
900.860.940.520.160.400.080.210.090.840.970.870.490.390.690.330.330.450.090.670.660.240.260.600.020.130.730.360.380.580.37
910.450.610.380.460.540.500.540.500.820.680.830.670.060.510.850.720.550.410.770.830.550.450.210.730.170.350.030.770.600.76
920.520.840.840.380.580.450.190.130.690.580.100.260.220.760.680.650.870.510.760.550.810.330.110.080.100.410.870.090.500.93
930.190.180.830.280.150.900.360.070.000.610.940.540.970.560.680.850.270.290.610.210.590.490.670.780.570.030.190.860.940.60
940.860.080.210.810.180.220.850.340.180.080.460.440.060.400.950.820.640.890.860.930.660.960.110.270.550.360.040.060.010.24
950.090.740.530.460.700.850.320.300.110.640.380.730.240.370.260.840.710.950.280.090.760.900.240.360.840.120.390.250.150.80
960.220.100.460.930.790.470.210.460.980.290.260.830.920.140.590.470.650.290.230.180.740.400.790.070.140.260.720.790.870.68
970.230.090.870.360.440.050.050.240.930.250.770.650.840.240.180.550.970.470.810.280.460.430.690.160.660.300.520.180.590.17
980.670.240.190.330.240.050.460.360.220.470.150.820.740.240.810.490.490.370.820.570.960.100.650.350.620.020.300.590.750.81
990.090.730.500.190.080.700.700.620.970.590.210.100.160.810.090.990.710.030.230.800.850.880.700.790.910.860.130.990.100.05

Reset display options to default

# Reset display options
pd.reset_option("^display")