# Tags
**Software** : [[Python]] [[ChatGPT]]
**Functions** used :
**Date** : 29-March-2025
# Description
# Video Link
<iframe width="560" height="315" src="https://www.youtube.com/embed/F-DiRR6IZLc?si=MZp2H3O4PZQT4xlV" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
[GITHUB File Link](https://github.com/jbotes/powerbiTutorials/blob/main/BaSensei_webscrape_Bitcoin_YTVideo.ipynb)
Scraped Website
!https://bitinfocharts.com/top-100-richest-bitcoin-addresses.html
# Python Code
```python
from bs4 import BeautifulSoup
import pandas as pd
import requests
import csv
#from pyspark.sql import dataframe
from datetime import datetime
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0", "Accept-Encoding":"gzip, deflate", "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "DNT":"1","Connection":"close", "Upgrade-Insecure-Requests":"1"}
url = 'https://bitinfocharts.com/top-100-richest-bitcoin-addresses.html'
response = requests.get(url,headers=headers).text
soup = BeautifulSoup(response, "html.parser")
# Find the table with the specified attributes
table = soup.find('table', {'class': 'table table-condensed bb', 'style': 'max-width:1000px;text-align:center;width: inherit;margin-bottom: 0;'})
# Extract the headers
headers = [th.text for th in table.find('thead').find_all('th')]
# Extract the rows
rows = []
for tr in table.find('tbody').find_all('tr'):
rows.append([td.text.strip() for td in tr.find_all('td')])
# Create a DataFrame
df = pd.DataFrame(rows, columns=headers)
# Add the current date and time column
df['Date and Time'] = pd.Timestamp.now().strftime('%d/%m/%Y %H:%M')
# Display the first few rows of the DataFrame
df.head()
# Split the "% Addresses (Total)" column by the "(" delimiter and keep only the first part
df['% Addresses (Total)'] = df['% Addresses (Total)'].apply(lambda x: x.split('(')[0].strip())
# Convert the values to percentage
df['% Addresses (Total)'] = df['% Addresses (Total)'].str.rstrip('%').astype('float') / 100
# Display the updated DataFrame
df.head()
# Remove the "BTC" string and commas from the "Coins" column, then convert to decimal data type
df['Coins'] = df['Coins'].replace('[BTC,]', '', regex=True).astype(float)
# Round the values to 2 decimal places
df['Coins'] = df['Coins'].round(2)
# Display the updated DataFrame
df.head()
# Split the "% Coins (Total)" column by the "(" delimiter and keep only the first part
df['% Coins (Total)'] = df['% Coins (Total)'].apply(lambda x: x.split('(')[0].strip())
# Convert the values to percentage
df['% Coins (Total)'] = df['% Coins (Total)'].str.rstrip('%').astype('float') / 100
# Display the updated DataFrame
df.head()
# Define the path for the CSV file
csv_file_path = "bitcoin_wealth_distribution.csv"
# Save the DataFrame to a CSV file
df.to_csv(csv_file_path, index=False)
```
## Optional Tags
**Tags** :
**Technique** :