I have a google sheet with a filter/query that only shows the data that verifies the filter's conditions. To retrieve the data for python I use gspread, but hiddenrows are appearing too (as if there was no filter at all).
How can I differentiate the rows selected from the ones who weren't?
I don't understand if this can work without adding more functions to gspread, or if I need to create a new function. If so, what should the function be?
I found that function fetch_sheet_metadata() which is inside class spreadsheet of gspread gives out the filters and hiddenValues for each filter, which is enough to solve my problem.
Related
I used the smartsheet-python-sdk (with a unique API key from Smartsheet) to automatically pull data from Smartsheet into my Python script along with other data sources (from Tableau) to create new feature-engineered columns. I now want to put these new columns I've created back into the same Smartsheet file I initially pulled from. Is there an automatic way to put these new columns I created back into the same Smartsheet I initially pulled data from using the smartsheet-python-sdk? Thank you!
Yes, the REST API documentation shows how to do it via the Python API in the examples on the right sidebar.
I find the Python API woefully under-documented, but a) it closely parallels the REST API with a few differences, like parameters being in Pythonic snake_case instead of JS camelCase; and b) the examples are usually enough to get you there.
Currently using gspread and python. Currently to update values on my spreadsheet I have to grab values from sheet, update them and then write back.
What i am looking for is...say I have a cell with a value of 5, is there a way to make an api call that says add +5 to "x" cell? I would no longer need to grab the values first, which even saves an api call. I don't know if this command is available or anything similar is, but would appreciate any help here!
Poring over both the documentation for gspread and the Sheets API I'm fairly confident that this cannot be done. All the methods that update values on a sheet require you to specify a range and the list of values, but you are unable to refer to the current values within the range without first retrieving them.
Your best way to reduce API calls is to just retrieve and update the data in batches as much as possible using batch_get() and batch_update().
If you'd like to submit feedback to Google to implement something like this in a future API update you can check out their issue tracker.
I am trying to parse through an Excel sheet that has columns for the website name (column A), the number of visitors (F), a contact at that website's first name (B), one for last name (C), for email (E), and date it was last modified (L).
I want to write a python script that goes through the sheet and looks at sites that have been modified in the last 3 months and prints out the name of the website and an email.
It is pretty straightforward to do this. I think a little bit of googling can help you a lot. But in short, you need to use a library called Pandas which is a really powerful tool for handling spreadsheets, datasets, and table-based files.
Pandas documentation is very well written. You can use the tutorials provided within the documentation to work your way through the problem easily. However, I'll give you a brief overview of what you should do.
First open the spreadsheet (excel file) inside python using Pandas and load it into a data frame (read the docs and you'll understand).
Second Using one of the methods provided by pandas called where (actually there are a couple of methods) you can easily set a condition (like if date is older than some data) and get the masked data frame (which represents your spreadsheet) back from the method.
I'm attempting to filter data down by page path which is simple enough in most cases. However, I'm getting an unexpected result returned:
data = service.data().ga().get(
ids='ga:' + profile_id,
start_date='2018-06-15',
end_date='yesterday',
metrics='ga:sessions,ga:newUsers,ga:sessionDuration,ga:goal12Completions,ga:goal4Completions,ga:goal5Completions,ga:bounces,ga:users',
dimensions='ga:date,ga:sourceMedium,ga:userType,ga:country,ga:region,ga:city,ga:pagePath',
sort='ga:date',
filters='ga:pagePath=~/path1/path2.*',
start_index=index,
max_results=10000).execute()
return data
The data within Analytics has page data structured thus:
domain.com/path1/path2/
domain.com/path1/path2/some
domain.com/path1/path2/extra
domain.com/path1/path2/parameters
I expect the filter above to return data for each of these page structures, however, it only returns data for pages that have a parameter after path 2:
domain.com/path1/path2/some
domain.com/path1/path2/extra
domain.com/path1/path2/parameters
I've tried various ways to filter this data including:
filters='ga:pagePath=#/path1/path2'
filters='ga:pagePath=#/path2'
I've also attempted to pass in the search string as a variable into the filter which produced the same result.
I've also tested it out in the query explorer which gives the same results as my script. However, filtering for the same regex expression in the advanced filter area of GA gives me the results I expect from the first bullet list above. I also threw some of the data into a text file and did a regex search on it which gave me all of the expected results.
My next step is testing taking away specific metrics to see if there's a combination creating a problem but there shouldn't be according to the documentation.
Any suggestions on next steps for debugging or a correction of the filter?
Adjusting the filtering to a "contains substring" method will solve your problem. Refer to the Google Analytics API reference guide to see all of the available filtering options. Also, I would highly recommend double-checking your original data source within the Google Analytics user interface to ensure the URLs that you're seeking are in fact available.
filters='ga:pagePath=#<YOUR-SUBSTRING>',
I am using the Google Spreadsheets API in python, and I can't get the column headers for the ListView of a worksheet.
Does anyone know how to get those titles? I can only find the underscore preceded hashes.
Take a look at a this library I created, its a simple wrapper to the spreadsheet API designed to make cases like the one you are facing much simpler to deal with.