Like %who, but gives some extra information about each variable. The same type filtering of %who can be applied here. For all variables, the type is printed. Additionally it prints: - For {},[],(): their length. - For numpy arrays, a summary with shape, number
(self, parameter_s='')
| 350 | @skip_doctest |
| 351 | @line_magic |
| 352 | def whos(self, parameter_s=''): |
| 353 | """Like %who, but gives some extra information about each variable. |
| 354 | |
| 355 | The same type filtering of %who can be applied here. |
| 356 | |
| 357 | For all variables, the type is printed. Additionally it prints: |
| 358 | |
| 359 | - For {},[],(): their length. |
| 360 | |
| 361 | - For numpy arrays, a summary with shape, number of |
| 362 | elements, typecode and size in memory. |
| 363 | |
| 364 | - For DataFrame and Series types: their shape. |
| 365 | |
| 366 | - Everything else: a string representation, snipping their middle if |
| 367 | too long. |
| 368 | |
| 369 | Examples |
| 370 | -------- |
| 371 | Define two variables and list them with whos:: |
| 372 | |
| 373 | In [1]: alpha = 123 |
| 374 | |
| 375 | In [2]: beta = 'test' |
| 376 | |
| 377 | In [3]: df = pd.DataFrame({"a": range(10), "b": range(10,20)}) |
| 378 | |
| 379 | In [4]: s = df["a"] |
| 380 | |
| 381 | In [5]: %whos |
| 382 | Variable Type Data/Info |
| 383 | -------------------------------- |
| 384 | alpha int 123 |
| 385 | beta str test |
| 386 | df DataFrame Shape: (10, 2) |
| 387 | s Series Shape: (10, ) |
| 388 | """ |
| 389 | |
| 390 | varnames = self.who_ls(parameter_s) |
| 391 | if not varnames: |
| 392 | if parameter_s: |
| 393 | print('No variables match your requested type.') |
| 394 | else: |
| 395 | print('Interactive namespace is empty.') |
| 396 | return |
| 397 | |
| 398 | # if we have variables, move on... |
| 399 | |
| 400 | # for these types, show len() instead of data: |
| 401 | seq_types = ['dict', 'list', 'tuple'] |
| 402 | |
| 403 | # for numpy arrays, display summary info |
| 404 | ndarray_type = None |
| 405 | if 'numpy' in sys.modules: |
| 406 | try: |
| 407 | from numpy import ndarray |
| 408 | except ImportError: |
| 409 | pass |