
You should be able to control grouping and sorting using the applicable methods for the dataframe object. But I’m very much aware that most databases don’t guarantee an order and I’m not 100% sure files read into Tableau Prep data flows come with any guarantee either. Note: in every case I tested (which wasn’t many), the index matched the order of rows from the file. It doesn’t matter what the value is, I’ll overwrite it with the Python script.
#TABLEAU PREP AUTOMATE REFRESH CODE#
I can simply add the field as a calculation in a previous step, using code like 0 or INT(NULL) to give me a numeric field.

That of course requires such a column in the data – and it must be an integer. What it does is to apply an index to the column Index. But in the meantime, Python gives us a way to approach the problem. In fact, being able to number rows or add an index would be so useful, I’ve requested (and you can vote for) the idea of having it be a built-in part of Tableau Prep. The ability to assign a unique, sequential value to rows in the data set has innumerable uses and sometimes a row number encodes data about the record that you need. But for now, Python gives me a way to overcome some of the more complex challenges I have faced with my data…Īnd with that, let’s turn our attention to some examples of useful scripts: Adding Row Number / Index to the Data I’m sure some of the capabilities I’ve created with Python scripts will be built into Tableau Prep and available via a single click or two.

Instead, I wanted to share some of the scripts I’ve created to fill in some gaps that Tableau Prep currently has (after all, it’s less than 1.5 years old).

#TABLEAU PREP AUTOMATE REFRESH HOW TO#
My goal in this post, is not to describe how to install Python, or TabPy (the Tableau Python engine) or how to use PIP to install the Pandas module - all of that documentation is available when you join the beta program and I’m sure will be available when the production version lands. (and for those of you who love R, you can use it too!) One of the coolest new features is the ability to use Python in Tableau Prep, giving you the ability to transform your data with Python Scripts. Tableau Prep Builder 2019.3 is currently in beta and I’m loving it! (along with all the other goodies: Tableau Desktop, Tableau Server, Tableau Catalog, Project McKinley).
