This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="table table-hover table-bordered" id="tableID" style="margin-bottom: 10px;"> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
url = "http://bank-code.net/country/FRANCE-%28FR%29/" | |
page = requests.get(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bs4 | |
soup = bs4.BeautifulSoup(page.content, 'lxml') | |
table = soup.find(name='table', attrs={'id':'tableID'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = pd.DataFrame([[td.text for td in row.findAll('td')] for row in table.tbody.findAll('tr')]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="//bank-code.net/country/FRANCE-%28FR%29/15" data-ci-pagination-page="2" rel="next">></a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"http:" + soup.find('a', attrs={'rel':'next'}).get('href') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, bs4, requests | |
import pandas as pd | |
PATH = os.path.join("C:\\","Users","xxx","Documents","py") # you need to change to your local path | |
res = pd.DataFrame() | |
url = "http://bank-code.net/country/FRANCE-%28FR%29/" | |
counter = 0 | |
def table_to_df(table): | |
return pd.DataFrame([[td.text for td in row.findAll('td')] for row in table.tbody.findAll('tr')]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.ensemble import RandomForestClassifier # from xgboost import XGBClassifier | |
model = RandomForestClassifier() # XGBClassifier() | |
model.fit(X, y) | |
pd.DataFrame({'Variable':X.columns, | |
'Importance':model.feature_importances_}).sort_values('Importance', ascending=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = X_test.copy() | |
df['predictions'] = rf_model.predict_proba(X_test) | |
data_to_analyze = df.sort_values('predictions', ascending=False).head(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = X_test.copy()df['predictions'] | |
rf_model.predict_proba(X_test) | |
data_to_analyze = df.sort_values('predictions', ascending=False).head(10) |
OlderNewer