#!/usr/bin/env python # coding: utf-8 # >### 🚩 *Create a free WhyLabs account to get more value out of whylogs!*
# >*Did you know you can store, visualize, and monitor whylogs profiles with the [WhyLabs Observability Platform](https://whylabs.ai/whylogs-free-signup?utm_source=whylogs-Github&utm_medium=whylogs-example&utm_campaign=Logging_Different_Data)? Sign up for a [free WhyLabs account](https://whylabs.ai/whylogs-free-signup?utm_source=whylogs-Github&utm_medium=whylogs-example&utm_campaign=Logging_Different_Data) to leverage the power of whylogs and WhyLabs together!* # # (why)Logging # [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/whylabs/whylogs/blob/mainline/python/examples/basic/Logging_Different_Data.ipynb) # WhyLogs enables logging different types of data that can then be used to monitor the data. We'll go through examples on different types of data to log and go more in depth on different options. Before we get going though, let's import whylogs. # In[5]: # Note: you may need to restart the kernel to use updated packages. get_ipython().run_line_magic('pip', 'install whylogs') # ## Table of Contents # #### [Log Pandas Dataframe](#log_dataframe) | [Log Dictionary](#log_dict) | [Display Logs](#display) # ## Log Pandas DataFrame # # We will be generating log by importing data from a CSV into Pandas Dataframe, logging it with the whylogs python library. # In[6]: import os.path import pandas as pd # Read in a CSV, this one is from a public bucket on s3 retail_daily = pd.read_csv('https://whylabs-public.s3.us-west-2.amazonaws.com/whylogs_examples/retail-daily-features.csv') retail_daily # In[7]: import whylogs as why # Log the data frame. This equivalent to why.log(retail_daily) and why.log(data=retail_daily) results = why.log(pandas=retail_daily) # Get the Results profile = results.profile() # Head down to Display a Log for explination profile.view().to_pandas() # ## Log Dictionary # # Sometimes a quick log is all you need though and don't want to set up a DataFrame. We can log a dictionary as if it were a single row of data. This works best when the values of that dictionary are scalar data, any collection values or nested values will be tracked with only a basic type counter and these entries get mapped to the object count. # # Suppose we want to log art prints that are being shown to see what sells best. # # In[8]: import whylogs as why example_data = {"height": 100, "length": 1000, "status": "sold", "price": 58.00, "medium": ["watercolor", "digital"] } # Log the dictionary this is equivalent to why.log(example_data) dict_results = why.log(row=example_data) # Retrieve the profile profile_from_dict = dict_results.profile() # Head to Display Logs to explain profile_from_dict.view().to_pandas() # ## Display the Logs # There are many ways to display the data! Examples in "Integrations", "WhyLabs", and "Use Cases" showcase how to use a variety of tools to see your data. Also the Notebook_Profile_Visualizer helps you display the profile with a variety of charts. # # Your log will from above returns results including the profile. It's this profile that we can view and export as a Pandas DataFrame. # In[9]: # Note run any of the examples above to get the results for this block #grab profile from result set profile = results.profile() #grab a 'view' of the profile for inspection prof_view = profile.view() #inspect profile as a Pandas DataFrame prof_df = prof_view.to_pandas() prof_df