forked from jvalue/made-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cee1f7c
commit a21a0f2
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import urllib.request | ||
import zipfile as ZipFile | ||
|
||
|
||
|
||
df = urllib.request.urlretrieve("https://www.mowesta.com/data/measure/mowesta-dataset-20221107.zip", 'zipfile') | ||
|
||
#zipresp = urlopen(zipurl) | ||
# Create a new file on the hard drive | ||
tempzip = open("/tmp/tempfile.zip", "wb") | ||
# Write the contents of the downloaded file into the new file | ||
tempzip.write(df.read()) | ||
# Close the newly-created file | ||
tempzip.close() | ||
# Re-open the newly-created file with ZipFile() | ||
zf = ZipFile("/tmp/tempfile.zip") | ||
# Extract its contents into <extraction_path> | ||
# note that extractall will automatically create the path | ||
zf.extractall(path = '///.exercises/') | ||
# close the ZipFile instance | ||
zf.close() | ||
'''#Download csv File | ||
df = pd.read_csv("data.csv",sep=';', decimal=',') | ||
#Drop Status column | ||
df = df.drop(['Status'], axis=1) | ||
#Then, drop all rows with invalid values in Verkehr: | ||
df = df[df['Verkehr'].isin(['FV','RV','nur DPN'])] | ||
#>= or > is enough | ||
df = df[(df['Laenge']>= -90 )& (df['Laenge']<= 90) & (df['Breite']>= -90 )& (df['Breite']<= 90) ] | ||
#Valid "IFOPT" values follow this pattern: | ||
#<exactly two characters>:<any amount of numbers>:<any amount of numbers><optionally another colon followed by any amount of numbers> | ||
df = df[df['IFOPT'].str.contains(r'^[A-Za-z]{2}:\d*:\d*(?::\d*)?$',na=False)] | ||
#Change empty cells to nan | ||
df.replace('',np.nan, inplace=True) | ||
#Drop nan cells | ||
df.dropna(inplace=True) | ||
#Convert column 'Betreiber_Nr' to integer | ||
df['Betreiber_Nr'] = df['Betreiber_Nr'].astype(int) | ||
#Write to sqlite | ||
df.to_sql('trainstops', 'sqlite:///trainstops.sqlite', if_exists= 'replace', index=False) | ||
''' |