Skip to content

Instantly share code, notes, and snippets.

View FelixChop's full-sized avatar

Félix Revert FelixChop

View GitHub Profile
@FelixChop
FelixChop / element.html
Last active June 1, 2018 09:35
element.html
<table class="table table-hover table-bordered" id="tableID" style="margin-bottom: 10px;">
</table>
import requests
url = "http://bank-code.net/country/FRANCE-%28FR%29/"
page = requests.get(url)
import bs4
soup = bs4.BeautifulSoup(page.content, 'lxml')
table = soup.find(name='table', attrs={'id':'tableID'})
result = pd.DataFrame([[td.text for td in row.findAll('td')] for row in table.tbody.findAll('tr')])
<a href="//bank-code.net/country/FRANCE-%28FR%29/15" data-ci-pagination-page="2" rel="next">&gt;</a>
"http:" + soup.find('a', attrs={'rel':'next'}).get('href')
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')])
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)
df = X_test.copy()
df['predictions'] = rf_model.predict_proba(X_test)
data_to_analyze = df.sort_values('predictions', ascending=False).head(10)
df = X_test.copy()df['predictions']
rf_model.predict_proba(X_test)
data_to_analyze = df.sort_values('predictions', ascending=False).head(10)