Skip to content

Instantly share code, notes, and snippets.

@jcdevilleres
Created August 17, 2020 16:00
Show Gist options
  • Save jcdevilleres/e8bf8219c0f718d7ea4fd533629cf447 to your computer and use it in GitHub Desktop.
Save jcdevilleres/e8bf8219c0f718d7ea4fd533629cf447 to your computer and use it in GitHub Desktop.
Using Python pandas script as flow in your Tableau Prep!
# This is a sample pandas script which you can integrate with your Tableau Prep flow
# 'import pandas as pd' can be skipped as it is already loaded on your server
# 'df is your input dataset' which you connected
def get_data(df):
return df.head(100)
def drop_duplicates(df):
return df.drop_duplicates()
def get_bottom_n(df):
return df.tail(n=100)
def get_top_n(df):
return df.head(n=100)
def get_sample_n(df):
return df.sample(n=50)
# If you want to get different fields / columns from the input
# you have to define the schema using the get_output_schema function
# this tells Tableau Prep how to format your data
def get_columns(df):
out_df = df.query('Discount == 0')
return out_df[['Discount','Days to Ship']]
def get_output_schema():
return pd.DataFrame({
'Discount' : prep_int(),
'Days to Ship' : prep_int()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment