magic_command

In [1]:
import pandas as pd
import numpy as np
In [11]:
df = pd.DataFrame(np.random.randint(1, 3, size=(2, 3)), columns=list("abc"))
df
Out[11]:
a b c
0 1 2 1
1 1 1 1
In [12]:
df.insert(1, "d", "value")
df.insert(3, "e", [100, 200])
df
Out[12]:
a d b e c
0 1 value 2 100 1
1 1 value 1 200 1
In [3]:
%%perl
my $a = 1;
sub add {
   my ($x, $y) = @_;
   return $x + $y;
}
print $a + add(2, 3);
6
In [8]:
%pdoc df.insert
In [24]:
%pdoc df
In [25]:
%pdoc pd
In [5]:
?df.insert
In [27]:
%pdef  df.insert
 df.insert(loc, column, value, allow_duplicates=False)

In [52]:
%pinfo df.insert
In [34]:
%pinfo df
In [38]:
%pinfo pd
In [53]:
%pinfo2 df.insert
In [ ]:
%pinfo df
In [ ]:
%pinfo pd
In [39]:
%pfile df.insert
In [43]:
%pfile df
In [42]:
%pfile pandas
Object `pandas` not found.
File `'pandas.py'` not found.
In [23]:
%psource df.insert
In [102]:
%psource df
In [45]:
%psource pd
In [47]:
%pprint
list(range(100))
Pretty printing has been turned OFF
Out[47]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
In [63]:
%pprint
Pretty printing has been turned ON
In [55]:
%pycat https://raw.githubusercontent.com/pydata/pandas/master/setup.py
In [61]:
import os
os.environ.get("myenv")
In [75]:
%set_env myenv=value
env: myenv=value
In [ ]:
os.environ.get("myenv")
In [76]:
%env myenv
Out[76]:
'value'
In [64]:
%alias
Total number of aliases: 12
Out[64]:
[('cat', 'cat'),
 ('cp', 'cp'),
 ('ldir', 'ls -F -G -l %l | grep /$'),
 ('lf', 'ls -F -l -G %l | grep ^-'),
 ('lk', 'ls -F -l -G %l | grep ^l'),
 ('ll', 'ls -F -l -G'),
 ('ls', 'ls -F -G'),
 ('lx', 'ls -F -l -G %l | grep ^-..x'),
 ('mkdir', 'mkdir'),
 ('mv', 'mv'),
 ('rm', 'rm'),
 ('rmdir', 'rmdir')]
In [66]:
%alias_magic -l
UsageError: the following arguments are required: name, target
In [98]:
%doctest_mode
Exception reporting mode: Plain
Doctest mode is: ON
In [91]:
import doctest
In [97]:
>>> 1+1
Out[97]:
2
In [99]:
%quickref
In [100]:
%edit

IPython will make a temporary file named: /var/folders/zl/rlmkmk5d3vv_jb8397gd61900000gn/T/ipython_edit_4y11vc7l/ipython_edit_nocpa3f9.py
In [87]:
%pycat  /var/folders/zl/rlmkmk5d3vv_jb8397gd61900000gn/T/ipython_edit_itirbk4s/ipython_edit_m7rsd2yh.py
In [ ]:

In [ ]: