Question: I am having some issues web scraping some data with beautiful soup and I am wondering if any of you scraper pros could give me some guidance.

This is the exact web page I would like to scrape:
<https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20171013>

Specifically, I'd like to grab the table of historical prices and somehow extract the information into a DataFrame. But first I need to actually find it within the raw html.

```
import requests
from bs4 import BeautifulSoup

data = requests.get('https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20171013') 

soup = BeautifulSoup(data._content, 'html.parser')

```

Unfortunately, I'm getting an encoding error

```
UnicodeEncodeError: 'ascii' codec can't encode character '\xa0' in position 22075: ordinal not in range(128)

```

Is there a way to basically just strip out all of the characters that can't be encoded before passing the raw html to beautiful soup?

Answer: 
By using `stack`

```
df.set_index(['ID_Patient','Name_Patient']).stack().reset_index()
Out[254]: 
    ID_Patient Name_Patient     level_2  0
0        11132          Jim  Visits_Jan  2
1        11132          Jim  Visits_Feb  5
2        11132          Jim  Visits_Mar  0
3         2755         Jack  Visits_Jan  1
4         2755         Jack  Visits_Feb  0
5         2755         Jack  Visits_Mar  0
6         9753          Sue  Visits_Jan  0
7         9753          Sue  Visits_Feb  0
8         9753          Sue  Visits_Mar  4
9         8453          Tom  Visits_Jan  4
10        8453          Tom  Visits_Feb  1
11        8453          Tom  Visits_Mar  1
12        4872        James  Visits_Jan  2
13        4872        James  Visits_Feb  1
14        4872        James  Visits_Mar  2

```

PS: change the column name by using `.rename(columns={})`
Using `df.melt`

```
df.melt(id_vars=['ID_Patient', 'Name_Patient'],
        var_name='Month_of_visit', value_name='Col1')
#     ID_Patient Name_Patient Month_of_visit  Col1
# 0        11132          Jim     Visits_Feb     5
# 1         2755         Jack     Visits_Feb     0
# 2         9753          Sue     Visits_Feb     0
# 3         8453          Tom     Visits_Feb     1
# 4         4872        James     Visits_Feb     1
# 5        11132          Jim     Visits_Jan     2
# 6         2755         Jack     Visits_Jan     1
# 7         9753          Sue     Visits_Jan     0
# 8         8453          Tom     Visits_Jan     4
# 9         4872        James     Visits_Jan     2
# 10       11132          Jim     Visits_Mar     0
# 11        2755         Jack     Visits_Mar     0
# 12        9753          Sue     Visits_Mar     4
# 13        8453          Tom     Visits_Mar     1
# 14        4872        James     Visits_Mar     2

```