mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 15:13:55 +02:00
Executing black over all jupyter notebook (#190)
Reverting black for the jupyter notebooks gets old. Can we just run black over all of them?
This commit is contained in:
@ -82,7 +82,7 @@
|
||||
"# Download the lexicon\n",
|
||||
"nltk.download(\"vader_lexicon\")\n",
|
||||
"\n",
|
||||
"# Import the lexicon \n",
|
||||
"# Import the lexicon\n",
|
||||
"from nltk.sentiment.vader import SentimentIntensityAnalyzer\n",
|
||||
"\n",
|
||||
"# Create an instance of SentimentIntensityAnalyzer\n",
|
||||
@ -132,12 +132,22 @@
|
||||
"text_df = pd.DataFrame(\n",
|
||||
" [\n",
|
||||
" {\"text\": \"Microsoft fails to hit profit expectations.\"},\n",
|
||||
" {\"text\": \"Confidence continues to prevail on the stock market, as the performance of the DAX shows.\"},\n",
|
||||
" {\n",
|
||||
" \"text\": \"Confidence continues to prevail on the stock market, as the performance of the DAX shows.\"\n",
|
||||
" },\n",
|
||||
" {\"text\": \"Stocks rallied and the British pound gained.\"},\n",
|
||||
" {\"text\": \"Meyer Burger now serves Australian market and presents itself at Smart Energy Expo in Sydney.\"},\n",
|
||||
" {\"text\": \"Meyer Burger enters Australian market and exhibits at Smart Energy Expo in Sydney.\"},\n",
|
||||
" {\"text\": \"J&T Express Vietnam helps local craft villages increase their reach.\"},\n",
|
||||
" {\"text\": \"7 experts recommend the stock for purchase, 1 expert recommends holding the stock.\"},\n",
|
||||
" {\n",
|
||||
" \"text\": \"Meyer Burger now serves Australian market and presents itself at Smart Energy Expo in Sydney.\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"text\": \"Meyer Burger enters Australian market and exhibits at Smart Energy Expo in Sydney.\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"text\": \"J&T Express Vietnam helps local craft villages increase their reach.\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"text\": \"7 experts recommend the stock for purchase, 1 expert recommends holding the stock.\"\n",
|
||||
" },\n",
|
||||
" {\"text\": \"Microsoft share falls.\"},\n",
|
||||
" {\"text\": \"Microsoft share is rising.\"},\n",
|
||||
" ]\n",
|
||||
@ -262,22 +272,21 @@
|
||||
],
|
||||
"source": [
|
||||
"def format_output(output_dict):\n",
|
||||
" \n",
|
||||
" polarity = \"neutral\"\n",
|
||||
" polarity = \"neutral\"\n",
|
||||
"\n",
|
||||
" if(output_dict['compound']>= 0.05):\n",
|
||||
" polarity = \"positive\"\n",
|
||||
" if output_dict[\"compound\"] >= 0.05:\n",
|
||||
" polarity = \"positive\"\n",
|
||||
"\n",
|
||||
" elif(output_dict['compound']<= -0.05):\n",
|
||||
" polarity = \"negative\"\n",
|
||||
" elif output_dict[\"compound\"] <= -0.05:\n",
|
||||
" polarity = \"negative\"\n",
|
||||
"\n",
|
||||
" return polarity\n",
|
||||
" return polarity\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def predict_sentiment(text):\n",
|
||||
" \n",
|
||||
" output_dict = sent_analyzer.polarity_scores(text)\n",
|
||||
" return output_dict\n",
|
||||
" output_dict = sent_analyzer.polarity_scores(text)\n",
|
||||
" return output_dict\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Run the predictions\n",
|
||||
"text_df[\"vader_prediction\"] = text_df[\"text\"].apply(predict_sentiment)\n",
|
||||
|
@ -31,8 +31,9 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"url = 'https://www.tagesschau.de/api2/'\n",
|
||||
"r = requests.get(url +'homepage')\n",
|
||||
"\n",
|
||||
"url = \"https://www.tagesschau.de/api2/\"\n",
|
||||
"r = requests.get(url + \"homepage\")\n",
|
||||
"r = r.json()"
|
||||
]
|
||||
},
|
||||
@ -76,10 +77,11 @@
|
||||
"source": [
|
||||
"# Aggregieren der Titel und Beschreibungen\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"data = {\"titles\": [], \"description\": []}\n",
|
||||
"for i in range(len(r[\"news\"])): \n",
|
||||
" data[\"titles\"].append(r[\"news\"][i][\"title\"])\n",
|
||||
" data[\"description\"].append(r[\"news\"][i][\"content\"][0][\"value\"])\n",
|
||||
"for i in range(len(r[\"news\"])):\n",
|
||||
" data[\"titles\"].append(r[\"news\"][i][\"title\"])\n",
|
||||
" data[\"description\"].append(r[\"news\"][i][\"content\"][0][\"value\"])\n",
|
||||
"df = pd.DataFrame(data)\n",
|
||||
"print(df.__len__)"
|
||||
]
|
||||
@ -19323,7 +19325,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"r = requests.get(url +'news').json()\n",
|
||||
"r = requests.get(url + \"news\").json()\n",
|
||||
"r"
|
||||
]
|
||||
},
|
||||
@ -19355,8 +19357,8 @@
|
||||
],
|
||||
"source": [
|
||||
"data = {\"titles\": []}\n",
|
||||
"for i in range(len(r[\"news\"])): \n",
|
||||
" data[\"titles\"].append(r[\"news\"][i][\"title\"])\n",
|
||||
"for i in range(len(r[\"news\"])):\n",
|
||||
" data[\"titles\"].append(r[\"news\"][i][\"title\"])\n",
|
||||
"# data[\"description\"].append(r[\"news\"][i][\"content\"][0][\"value\"])\n",
|
||||
"df = pd.DataFrame(data)\n",
|
||||
"print(df)"
|
||||
@ -19391,7 +19393,7 @@
|
||||
],
|
||||
"source": [
|
||||
"date = \"230425\"\n",
|
||||
"r = requests.get(url +'newsfeed-101~_date-{date}.json').json()\n",
|
||||
"r = requests.get(url + \"newsfeed-101~_date-{date}.json\").json()\n",
|
||||
"r"
|
||||
]
|
||||
},
|
||||
@ -19989,7 +19991,7 @@
|
||||
"pageSize = 5\n",
|
||||
"resultPage = 2\n",
|
||||
"print(url)\n",
|
||||
"txt = f'search/?searchText={searchtxt}&pageSize={pageSize}&resultPage={resultPage}'\n",
|
||||
"txt = f\"search/?searchText={searchtxt}&pageSize={pageSize}&resultPage={resultPage}\"\n",
|
||||
"r = requests.get(url + txt).json()\n",
|
||||
"r"
|
||||
]
|
||||
|
@ -51,6 +51,7 @@
|
||||
],
|
||||
"source": [
|
||||
"from deutschland.bundesanzeiger import Bundesanzeiger\n",
|
||||
"\n",
|
||||
"ba = Bundesanzeiger()\n",
|
||||
"# search term\n",
|
||||
"data = ba.get_reports(\"Atos IT-Dienstleistung & Beratung GmbH\")\n",
|
||||
@ -73,11 +74,13 @@
|
||||
],
|
||||
"source": [
|
||||
"# Note: There can be multiple \"Aufsichtsrat\" entries per Company, the API however does only return one because the keys are overwritten\n",
|
||||
"jahresabschluss = data['Jahresabschluss zum Geschäftsjahr vom 01.01.2019 bis zum 31.12.2019']\n",
|
||||
"jahresabschluss = data[\n",
|
||||
" \"Jahresabschluss zum Geschäftsjahr vom 01.01.2019 bis zum 31.12.2019\"\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Note: Although the report includes the entire text it lacks the formatting that would make extracting information a lot easier as the data is wrapped inside a <table> originally\n",
|
||||
"with open(\"./jahresabschluss-example.txt\", \"w\") as file:\n",
|
||||
" file.write(jahresabschluss['report'])\n",
|
||||
" file.write(jahresabschluss[\"report\"])\n",
|
||||
"print(jahresabschluss.keys())"
|
||||
]
|
||||
},
|
||||
@ -96,6 +99,7 @@
|
||||
],
|
||||
"source": [
|
||||
"from deutschland.handelsregister import Handelsregister\n",
|
||||
"\n",
|
||||
"hr = Handelsregister()\n",
|
||||
"\n",
|
||||
"results = hr.search(keywords=\"BLUECHILLED Verwaltungs GmbH\")\n",
|
||||
@ -128,6 +132,7 @@
|
||||
"source": [
|
||||
"# SQLite export\n",
|
||||
"import sqlite3\n",
|
||||
"\n",
|
||||
"con = sqlite3.connect(\"../data/openregister.db\")"
|
||||
]
|
||||
},
|
||||
@ -176,7 +181,7 @@
|
||||
],
|
||||
"source": [
|
||||
"schema = cur.execute(\"SELECT name FROM sqlite_master WHERE type='table';\")\n",
|
||||
"schema.fetchall()\n"
|
||||
"schema.fetchall()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -414,6 +419,7 @@
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"df = pd.read_sql_query(\"SELECT * FROM company LIMIT 100\", con)\n",
|
||||
"df.head()"
|
||||
]
|
||||
|
@ -68,6 +68,7 @@
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"import ipywidgets as widgets\n",
|
||||
"\n",
|
||||
"pd.options.plotting.backend = \"plotly\""
|
||||
]
|
||||
},
|
||||
@ -86,9 +87,9 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dfEON=pd.read_csv('EON_Data.csv', index_col=0, sep=';') \n",
|
||||
"dfBASF=pd.read_csv('BASF_Data.csv', index_col=0, sep=';') \n",
|
||||
"dfTELEKOM=pd.read_csv('TELEKOM_Data.csv', index_col=0, sep=';') "
|
||||
"dfEON = pd.read_csv(\"EON_Data.csv\", index_col=0, sep=\";\")\n",
|
||||
"dfBASF = pd.read_csv(\"BASF_Data.csv\", index_col=0, sep=\";\")\n",
|
||||
"dfTELEKOM = pd.read_csv(\"TELEKOM_Data.csv\", index_col=0, sep=\";\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -112,7 +113,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#select a specific year\n",
|
||||
"# select a specific year\n",
|
||||
"dfTELEKOM.loc[2016]"
|
||||
]
|
||||
},
|
||||
@ -148,33 +149,34 @@
|
||||
],
|
||||
"source": [
|
||||
"def get_Data(company, metric):\n",
|
||||
" if company=='BASF':\n",
|
||||
" dfSelect=dfBASF\n",
|
||||
" print('BASF')\n",
|
||||
" if company=='EON':\n",
|
||||
" dfSelect=dfEON\n",
|
||||
" print('EON') \n",
|
||||
" if company=='Telekom':\n",
|
||||
" dfSelect=dfTELEKOM\n",
|
||||
" print('Telekom') \n",
|
||||
" fig=dfSelect.plot()\n",
|
||||
" fig.show() \n",
|
||||
" if company == \"BASF\":\n",
|
||||
" dfSelect = dfBASF\n",
|
||||
" print(\"BASF\")\n",
|
||||
" if company == \"EON\":\n",
|
||||
" dfSelect = dfEON\n",
|
||||
" print(\"EON\")\n",
|
||||
" if company == \"Telekom\":\n",
|
||||
" dfSelect = dfTELEKOM\n",
|
||||
" print(\"Telekom\")\n",
|
||||
" fig = dfSelect.plot()\n",
|
||||
" fig.show()\n",
|
||||
" return\n",
|
||||
"\n",
|
||||
"W_company=widgets.Dropdown(\n",
|
||||
" options=['BASF', 'EON', 'Telekom'],\n",
|
||||
" value='BASF',\n",
|
||||
" description='Company:',\n",
|
||||
"\n",
|
||||
"W_company = widgets.Dropdown(\n",
|
||||
" options=[\"BASF\", \"EON\", \"Telekom\"],\n",
|
||||
" value=\"BASF\",\n",
|
||||
" description=\"Company:\",\n",
|
||||
" disabled=False,\n",
|
||||
")\n",
|
||||
"W_metric=widgets.Dropdown(\n",
|
||||
" options=['EBIT', 'EBITDA', 'Volume'],\n",
|
||||
" value='Volume',\n",
|
||||
" description='Metric:',\n",
|
||||
"W_metric = widgets.Dropdown(\n",
|
||||
" options=[\"EBIT\", \"EBITDA\", \"Volume\"],\n",
|
||||
" value=\"Volume\",\n",
|
||||
" description=\"Metric:\",\n",
|
||||
" disabled=False,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"out=widgets.interact(get_Data, company=W_company, metric=W_metric)"
|
||||
"out = widgets.interact(get_Data, company=W_company, metric=W_metric)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user