Skip to content

Instantly share code, notes, and snippets.

import os
import pandas as pd
import fitz
from collections import Counter
import spacy
nlp = spacy.load('en_core_web_trf')
magazin_fol = "myfol/magazines/"
out_full_fp = "myfol/word_count_full.csv"
import pandas as pd
data_fol = "/myLocal/dataFol/"
# wc = wordcount. Make words lower case to make interpretation easier. Remove words that might still have <2 characters.
wc_df = pd.read_csv(data_fol + "word_count_full.csv", sep=";", decimal=",", encoding="utf8")
wc_df["word"] = wc_df["word"].str.lower()
wc_df = wc_df[wc_df["word"].str.len() > 2]
# convert str date column to pandas datetime format and extract months & years...
@jdegene
jdegene / date_df.csv
Last active September 28, 2022 18:05
Data examples for plotly dash tutorial
word date word_cnt_page
before 2017-06-21 2
before 2017-07-05 2
before 2017-10-11 1
before 2018-01-31 2
before 2018-02-14 2
before 2018-07-18 1
before 2018-09-26 1
before 2018-10-24 2
before 2018-11-07 1
# -*- coding: utf-8 -*-
# 1.0 Imports
import dash
from dash import dcc
from dash import html
from dash.dependencies import Output
from dash.dependencies import Input
sidebar = html.Div(
[ # add some header text
html.H2("My App", className="display-4",
style={'textAlign': 'center', 'font-variant': 'small-caps'}),
html.Hr(), # this adds a horizontal line
html.H3( # H3 is a smaller header than H2
"Data Analytics", className="display-8", style={'textAlign': 'center'}
),
# add the actual links
dbc.Nav(
# 3.1 PAGE 1
# store ALL of the following html in a variable page1_content. This is called when switching pages
# wrap everything in an out Div
page1_content = html.Div(
children=[
#header, this is a child of the outer div. All header information is then
# wrapped in its own Div
html.Div(
# 4.1 switch between pages. Each callback is connected to the function below
@app.callback(Output("page-content", "children"), # returns the page content of the clicked page
[Input("url", "pathname")]) # get the pathname from the url click as input
def render_page_content(pathname): # function input the the Input() parameter from the callback decorator
if pathname == "/":
return page1_content
elif pathname == "/page2_url":
return page2_content
# If the user tries to reach a different page, return an error message
return html.Div(
# 5 run the darn thing
if __name__ == "__main__":
# this will run the app on your local machine: basically dash will run
# its own dev server on localhost: visit 127.0.0.1:8050 in your browser to
# see your app
app.run_server(port=8050, debug=True)
#HOWEVER, if you are deploying it later, set your host to "0.0.0.0",
# because dash will not be responsible for managing the server itself
# -*- coding: utf-8 -*-
# 1.0 Imports
import dash
from dash import dcc
from dash import html
from dash.dependencies import Output
from dash.dependencies import Input