@@ -2278,9 +2278,11 @@ def info(
2278
2278
<class 'pandas.core.frame.DataFrame'>
2279
2279
RangeIndex: 5 entries, 0 to 4
2280
2280
Data columns (total 3 columns):
2281
- int_col 5 non-null int64
2282
- text_col 5 non-null object
2283
- float_col 5 non-null float64
2281
+ # Column Non-Null Count Dtype
2282
+ --- ------ -------------- -----
2283
+ 0 int_col 5 non-null int64
2284
+ 1 text_col 5 non-null object
2285
+ 2 float_col 5 non-null float64
2284
2286
dtypes: float64(1), int64(1), object(1)
2285
2287
memory usage: 248.0+ bytes
2286
2288
@@ -2319,19 +2321,23 @@ def info(
2319
2321
<class 'pandas.core.frame.DataFrame'>
2320
2322
RangeIndex: 1000000 entries, 0 to 999999
2321
2323
Data columns (total 3 columns):
2322
- column_1 1000000 non-null object
2323
- column_2 1000000 non-null object
2324
- column_3 1000000 non-null object
2324
+ # Column Non-Null Count Dtype
2325
+ --- ------ -------------- -----
2326
+ 0 column_1 1000000 non-null object
2327
+ 1 column_2 1000000 non-null object
2328
+ 2 column_3 1000000 non-null object
2325
2329
dtypes: object(3)
2326
2330
memory usage: 22.9+ MB
2327
2331
2328
2332
>>> df.info(memory_usage='deep')
2329
2333
<class 'pandas.core.frame.DataFrame'>
2330
2334
RangeIndex: 1000000 entries, 0 to 999999
2331
2335
Data columns (total 3 columns):
2332
- column_1 1000000 non-null object
2333
- column_2 1000000 non-null object
2334
- column_3 1000000 non-null object
2336
+ # Column Non-Null Count Dtype
2337
+ --- ------ -------------- -----
2338
+ 0 column_1 1000000 non-null object
2339
+ 1 column_2 1000000 non-null object
2340
+ 2 column_3 1000000 non-null object
2335
2341
dtypes: object(3)
2336
2342
memory usage: 188.8 MB
2337
2343
"""
@@ -2350,6 +2356,7 @@ def info(
2350
2356
return
2351
2357
2352
2358
cols = self .columns
2359
+ col_count = len (self .columns )
2353
2360
2354
2361
# hack
2355
2362
if max_cols is None :
@@ -2358,36 +2365,76 @@ def info(
2358
2365
max_rows = get_option ("display.max_info_rows" , len (self ) + 1 )
2359
2366
2360
2367
if null_counts is None :
2361
- show_counts = (len ( self . columns ) <= max_cols ) and (len (self ) < max_rows )
2368
+ show_counts = (col_count <= max_cols ) and (len (self ) < max_rows )
2362
2369
else :
2363
2370
show_counts = null_counts
2364
- exceeds_info_cols = len ( self . columns ) > max_cols
2371
+ exceeds_info_cols = col_count > max_cols
2365
2372
2366
2373
def _verbose_repr ():
2367
2374
lines .append (f"Data columns (total { len (self .columns )} columns):" )
2368
- space = max (len (pprint_thing (k )) for k in self .columns ) + 4
2375
+
2376
+ id_head = " # "
2377
+ column_head = "Column"
2378
+ col_space = 2
2379
+
2380
+ max_col = max (len (pprint_thing (k )) for k in cols )
2381
+ len_column = len (pprint_thing (column_head ))
2382
+ space = max (max_col , len_column ) + col_space
2383
+
2384
+ max_id = len (pprint_thing (col_count ))
2385
+ len_id = len (pprint_thing (id_head ))
2386
+ space_num = max (max_id , len_id ) + col_space
2369
2387
counts = None
2370
2388
2371
- tmpl = "{count}{dtype}"
2389
+ header = _put_str ( id_head , space_num ) + _put_str ( column_head , space )
2372
2390
if show_counts :
2373
2391
counts = self .count ()
2374
2392
if len (cols ) != len (counts ): # pragma: no cover
2375
2393
raise AssertionError (
2376
2394
f"Columns must equal counts ({ len (cols )} != { len (counts )} )"
2377
2395
)
2378
- tmpl = "{count} non-null {dtype}"
2396
+ count_header = "Non-Null Count"
2397
+ len_count = len (count_header )
2398
+ non_null = " non-null"
2399
+ max_count = max (len (pprint_thing (k )) for k in counts ) + len (non_null )
2400
+ space_count = max (len_count , max_count ) + col_space
2401
+ count_temp = "{count}" + non_null
2402
+ else :
2403
+ count_header = ""
2404
+ space_count = len (count_header )
2405
+ len_count = space_count
2406
+ count_temp = "{count}"
2407
+
2408
+ dtype_header = "Dtype"
2409
+ len_dtype = len (dtype_header )
2410
+ max_dtypes = max (len (pprint_thing (k )) for k in self .dtypes )
2411
+ space_dtype = max (len_dtype , max_dtypes )
2412
+ header += _put_str (count_header , space_count ) + _put_str (
2413
+ dtype_header , space_dtype
2414
+ )
2415
+
2416
+ lines .append (header )
2417
+ lines .append (
2418
+ _put_str ("-" * len_id , space_num )
2419
+ + _put_str ("-" * len_column , space )
2420
+ + _put_str ("-" * len_count , space_count )
2421
+ + _put_str ("-" * len_dtype , space_dtype )
2422
+ )
2379
2423
2380
- dtypes = self .dtypes
2381
2424
for i , col in enumerate (self .columns ):
2382
- dtype = dtypes .iloc [i ]
2425
+ dtype = self . dtypes .iloc [i ]
2383
2426
col = pprint_thing (col )
2384
2427
2428
+ line_no = _put_str (" {num}" .format (num = i ), space_num )
2385
2429
count = ""
2386
2430
if show_counts :
2387
2431
count = counts .iloc [i ]
2388
2432
2389
2433
lines .append (
2390
- _put_str (col , space ) + tmpl .format (count = count , dtype = dtype )
2434
+ line_no
2435
+ + _put_str (col , space )
2436
+ + _put_str (count_temp .format (count = count ), space_count )
2437
+ + _put_str (dtype , space_dtype )
2391
2438
)
2392
2439
2393
2440
def _non_verbose_repr ():
0 commit comments