Skip to content

Instantly share code, notes, and snippets.

View ebergam's full-sized avatar

Enrico Bergamini ebergam

  • Barcelona
View GitHub Profile
@ebergam
ebergam / ecb_indexer.py
Created January 9, 2021 12:13
Indexer for ECB press releases
from bs4 import BeautifulSoup as bs
import re, requests, time
from lxml import html
links = []
for date in range(1998, 2020+1):
url = 'https://www.ecb.europa.eu/press/pressconf/{}/html/index_include.en.html'.format(date)
r = requests.get(url)
tree = html.fromstring(r.content)
@ebergam
ebergam / google_trends.ipynb
Created October 9, 2020 08:48
Make queries from Gtrends and create time series
import pandas as pd
import os
import matplotlib.pyplot as plt
import missingno as msno
## The script merges and reshapes the data provided by https://github.com/kylemcdonald/covid-mobility-data
## Assumes all tsv files are in a folder called "archive"
## Inputs different files, outputs longform tidy data.
bdf = pd.read_csv('archive/2020-03-29_ES_Mobility_Report_en.pdf.tsv', sep='\t', nrows=0)
@ebergam
ebergam / movingscatter.py
Last active May 15, 2019 11:09
Moving Scatter
graph = px.scatter(df, x="employment", y="equity", #color="country",
hover_name="country", text="countrycode",
range_x=[48,80], range_y=[76,93], template="plotly_dark", size="pop",
animation_group="country", animation_frame="year",
labels=dict(employment="Emp", equity="Eq",year="Year"))
for i in graph['data']:
i['name'] = i['name'].replace('Country=', '')
# -*- coding: utf-8 -*-
import sys, re, time, logging, requests
import random
import unicodecsv as csv
from threading import Thread, Lock, currentThread
from queue import Queue, Empty
from lxml import html
lock = Lock()
<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<title>prova</title>
</head>
<body><div><style>
</style>
<iframe class='viz-container' src="https://public.tableau.com/profile/actionaid.bologna#!/vizhome/dashboard2017_0/Dashboard3?:embed=y"></iframe>
</div>
@ebergam
ebergam / aa.md
Last active April 24, 2018 13:25
prova

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

@ebergam
ebergam / pandapivot_big.py
Created February 6, 2018 09:23
Non-numeric pivot table reading data chunk by chunk
### Beware of the Panda.
### 'You have no idea how tidy this is gonna get'
from pandas import *
import csv
import numpy as np
df = pandas.read_csv(‘data_raw.csv’, sep=” “, chunksize=5000)
df
appended_data = []
for chunk in df:
pivot_table = chunk.pivot_table(index=[‘id’],
@ebergam
ebergam / pandapivot.py
Last active February 6, 2018 09:21
Non-numeric pivot tables in Pandas
import pandas as pd
import csv
df = pd.read_csv('data_raw.csv')
df
pivot_table = df.pivot_table(index=['id'],
columns=['key'],
values=['value'],
aggfunc=lambda x: ' '.join(str(v) for v in x))
pivot_table.to_csv('data_pivot.csv')
@ebergam
ebergam / python_to_ifttt.py
Created February 6, 2018 09:15
Connect a Python script to IFTTT
import requests
from bs4 import BeautifulSoup
url = ‘http://www.enricobergamini.it/trialpage.html'
#load and scrape
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, “lxml”)
number = soup.find(‘h1’, id=’number’).text