Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created January 18, 2021 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krokrob/8700958d70beb95355014dbce7685493 to your computer and use it in GitHub Desktop.
Save krokrob/8700958d70beb95355014dbce7685493 to your computer and use it in GitHub Desktop.
import os
import pandas as pd
class Olist:
def get_data(self):
"""
This function returns a Python dict.
Its keys should be 'sellers', 'orders', 'order_items' etc...
Its values should be pandas.DataFrame loaded from csv files
"""
# Hints: Build csv_path as "absolute path" in order to call this method from anywhere.
# Do not hardcode your path as it only works on your machine ('Users/username/code...')
# Use __file__ as absolute path anchor independant of your computer
# Make extensive use of `import ipdb; ipdb.set_trace()` to investigate what `__file__` variable is really
# Use os.path library to construct path independent of Unix vs. Windows specificities
csv_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data', 'csv')
file_names = [f for f in os.listdir(csv_path) if f.endswith('.csv')]
key_names = []
for f in file_names:
if f == 'product_category_name_translation.csv':
key_names.append('product_category_name_translation')
else:
key_names.append(f[6:-12])
data = {}
for k, f in zip(key_names, file_names):
data[k] = pd.read_csv(os.path.join(csv_path, f))
return data
def get_matching_table(self):
"""
01-01 > This function returns a matching table between
columns [ "order_id", "review_id", "customer_id", "product_id", "seller_id"]
"""
def ping(self):
"""
You call ping I print pong.
"""
print('pong')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment