Python for Spreadsheet Manipulation 101 - Hands-On Training for Salesforce Admins

Thanks for coding for THREE HOURS with me on a sunny Saturday!

Table of Contents

Homework

If I could give you one homework assignment, it’d be to get Python up and running on your computer.

If you can’t apply this to your real-world business problems, I’m going to cry.

And the number one thing that’s going to stop you isn’t lack of Python knowledge … it’s not having your tools “ready to go” when you think of a business problem you could solve using it.

Don’t make me cry.

As soon as you have both of those code snippets up and running, the world is at your fingertips!

Tweet me when you get it – #AwesomeAdmin & #YayUs !

DM me on Twitter if you get stuck.

Exercises We Did

Click here for the “Exercises” instructions

Slides PDF

Click here to download a PDF of the slides

Session Recording

IMPORTANT NOTE:

The links have changed! The links in the session recording are no longer guaranteed to be accurate! If they no longer work, or seem to be doing something different, it’s because I reused them for another presentation!

Replacement links are available with a “201810-“ after the “sfpy” but before the rest of the URL.

So …/sfpyhello becomes …/sfpy201810-hello and …/sfpyhello-b becomes …/sfpy201820-hello-b

Click here for session video

(Click here for session video)

Further Resources

Door Prize Scripts

Hopefully you can use these at work yesterday.

Tweet me if you use these in real life – #AwesomeAdmin & #YayUs !

Duplicate Summarizer

This script, once you give it the location of your CSV file on line 3 and the the set of column names that make up your “duplicate matching key” on line 4, will tell you 5 useful things:

  1. How many rows are a “duplicate” of some other row
  2. How many “groups” of duplicates there are in your CSV file
  3. How many total rows there are in your CSV file
  4. What the “duplicated” rows say in them
  5. What the “nature of the groups” are (e.g. if you’re grouping on “FirstName” & “LastName,” a table showing you things like “John Smith,” “Jane Doe,” etc.)
import pandas
pandas.set_option('expand_frame_repr', False)
filename = 'c:\\example\\sample.csv' # Edit this before running
dupeColumns = ['col1','col2','col3'] # Edit this before running
df = pandas.read_csv(filename, dtype=object)
isDupeSeries = df.duplicated(dupeColumns, keep=False)
isFirstDupeSeries = df.duplicated(dupeColumns, keep='first')
print(str(isDupeSeries.sum()) + ' dupes in ' + 
      str(isFirstDupeSeries.sum()) + ' groups in ' + 
      str(len(df)) + ' rows')
print('\r\n---The duped rows are:---')
print(df[isDupeSeries])
print('\r\n---The "dupe keys" are:---')
print(df[isFirstDupeSeries][dupeColumns])