Open a terminal or command-line window, start the ipython interpreter, and run the same commands that you ran in your example. This will give you the following pretty formatted output which you can copy/paste as plain text.
To format a block of text as code, select the block of code to be formatted with the mouse and click the pair of curly brackets {} in the Stack Overflow markdown editor to format the selected text as a code block or surround with groups of three backticks. Each group of backticks should be positioned on a separate line as shown in this example.
```
Markdown and HTML are turned off in code blocks
```
To highlight a block of text as Python code, precede the block of Python code with the following HTML comment followed by a blank space: <!-- language: python -->
$ ipython
Python 2.7.15rc1
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import pandas as pd
...: df1 = pd.DataFrame({'item_id':[1,2,1,1,2],
...: 'shop_id':['S1', 'S1', 'S1', 'S2', 'S2'],
...: 'price':[10, 20, 10, 12, 18]})
...: df1
...:
Out[1]:
item_id price shop_id
0 1 10 S1
1 2 20 S1
2 1 10 S1
3 1 12 S2
4 2 18 S2
In [2]: df2 = pd.DataFrame({'shop_id':['S1', 'S2'],
...: 'shop_name':['shop1', 'shop2']})
...: df2
...:
Out[2]:
shop_id shop_name
0 S1 shop1
1 S2 shop2
In [3]: shop_map = {shop_id:shop_name for shop_id,shop_name in zip(df2.shop_id,
...: df2.shop_name)}
...: shop_map
...:
Out[3]: {'S1': 'shop1', 'S2': 'shop2'}
In [4]: df1['shop_name'] = df1['shop_id'].apply(lambda shop_id: shop_map[shop_id
...: ])
...: df1
...:
Out[4]:
item_id price shop_id shop_name
0 1 10 S1 shop1
1 2 20 S1 shop1
2 1 10 S1 shop1
3 1 12 S2 shop2
4 2 18 S2 shop2
In [5]: