Loop through sheets and append columns










0















I have over 100 sheets in a smartsheet workspace. I'd like to use the python api to loop through each sheet and append the row id, sheet id, and the primary column into an array or pandas data frame.



import requests
import pandas as pd
import io
import warnings
warnings.filterwarnings(action='once')
import smartsheet
import os.path
from time import gmtime, strftime
import pandas as pd
import numpy as np
import json
import requests
import hashlib

fullList = pd.DataFrame()

for sheet in sheetArray:
r = requests.get(baseURL + "/" + str(sheet), headers=headers)
rows = json.loads(r.text)
rows = rows['rows']
rowsDF = pd.DataFrame.from_dict(rows)
dropCols = ["cells","createdAt", "expanded", "modifiedAt","siblingId"]
rowsDF = rowsDF.drop(dropCols, axis=1)
fullList.append(rowsDF)









share|improve this question
























  • Hi AME! What have you tried so far? Happy to help, but not sure where you're stuck.

    – stmcallister
    Nov 15 '18 at 19:16











  • @stmcallister - thanks, I updated the code I above.

    – AME
    Nov 15 '18 at 19:44















0















I have over 100 sheets in a smartsheet workspace. I'd like to use the python api to loop through each sheet and append the row id, sheet id, and the primary column into an array or pandas data frame.



import requests
import pandas as pd
import io
import warnings
warnings.filterwarnings(action='once')
import smartsheet
import os.path
from time import gmtime, strftime
import pandas as pd
import numpy as np
import json
import requests
import hashlib

fullList = pd.DataFrame()

for sheet in sheetArray:
r = requests.get(baseURL + "/" + str(sheet), headers=headers)
rows = json.loads(r.text)
rows = rows['rows']
rowsDF = pd.DataFrame.from_dict(rows)
dropCols = ["cells","createdAt", "expanded", "modifiedAt","siblingId"]
rowsDF = rowsDF.drop(dropCols, axis=1)
fullList.append(rowsDF)









share|improve this question
























  • Hi AME! What have you tried so far? Happy to help, but not sure where you're stuck.

    – stmcallister
    Nov 15 '18 at 19:16











  • @stmcallister - thanks, I updated the code I above.

    – AME
    Nov 15 '18 at 19:44













0












0








0








I have over 100 sheets in a smartsheet workspace. I'd like to use the python api to loop through each sheet and append the row id, sheet id, and the primary column into an array or pandas data frame.



import requests
import pandas as pd
import io
import warnings
warnings.filterwarnings(action='once')
import smartsheet
import os.path
from time import gmtime, strftime
import pandas as pd
import numpy as np
import json
import requests
import hashlib

fullList = pd.DataFrame()

for sheet in sheetArray:
r = requests.get(baseURL + "/" + str(sheet), headers=headers)
rows = json.loads(r.text)
rows = rows['rows']
rowsDF = pd.DataFrame.from_dict(rows)
dropCols = ["cells","createdAt", "expanded", "modifiedAt","siblingId"]
rowsDF = rowsDF.drop(dropCols, axis=1)
fullList.append(rowsDF)









share|improve this question
















I have over 100 sheets in a smartsheet workspace. I'd like to use the python api to loop through each sheet and append the row id, sheet id, and the primary column into an array or pandas data frame.



import requests
import pandas as pd
import io
import warnings
warnings.filterwarnings(action='once')
import smartsheet
import os.path
from time import gmtime, strftime
import pandas as pd
import numpy as np
import json
import requests
import hashlib

fullList = pd.DataFrame()

for sheet in sheetArray:
r = requests.get(baseURL + "/" + str(sheet), headers=headers)
rows = json.loads(r.text)
rows = rows['rows']
rowsDF = pd.DataFrame.from_dict(rows)
dropCols = ["cells","createdAt", "expanded", "modifiedAt","siblingId"]
rowsDF = rowsDF.drop(dropCols, axis=1)
fullList.append(rowsDF)






smartsheet-api smartsheet-api-2.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 14:13









stmcallister

1,3871815




1,3871815










asked Nov 15 '18 at 4:27









AMEAME

1,934175676




1,934175676












  • Hi AME! What have you tried so far? Happy to help, but not sure where you're stuck.

    – stmcallister
    Nov 15 '18 at 19:16











  • @stmcallister - thanks, I updated the code I above.

    – AME
    Nov 15 '18 at 19:44

















  • Hi AME! What have you tried so far? Happy to help, but not sure where you're stuck.

    – stmcallister
    Nov 15 '18 at 19:16











  • @stmcallister - thanks, I updated the code I above.

    – AME
    Nov 15 '18 at 19:44
















Hi AME! What have you tried so far? Happy to help, but not sure where you're stuck.

– stmcallister
Nov 15 '18 at 19:16





Hi AME! What have you tried so far? Happy to help, but not sure where you're stuck.

– stmcallister
Nov 15 '18 at 19:16













@stmcallister - thanks, I updated the code I above.

– AME
Nov 15 '18 at 19:44





@stmcallister - thanks, I updated the code I above.

– AME
Nov 15 '18 at 19:44












1 Answer
1






active

oldest

votes


















3














I'm not sure about pandas, but I can help you get the information into a python array.



Using the Smartsheet Python SDK you'll want to first install the SDK, then import smartsheet.



Next, initialize a Smartsheet object with your access token like so



ss_client = smartsheet.Smartsheet(SMARTSHEET_ACCESS_TOKEN)


Grab your Workspace



workplace = ss_client.Workspaces.get_workspace(workplace_id)


Grab the sheets from the Workspace



wp_sheets = workplace.sheets


Initialize the array you're creating



info_array = 


Loop over the sheets from the Workspace object. These sheet objects only have a few fields to identify the sheet, so you'll need to use the sheet.id to get the full sheet from the Smartsheet API.



# loop through sheets 
for sheet in wp_sheets:
# get sheet
full_sheet = ss_client.Sheets.get_sheet(sheet.id)


Grab the primary column for the sheet



# get the primary column
primary_column_id = get_primary_column_id(full_sheet.columns)


The get_primary_column_id() function would look like this. The column objects have a boolean field for primary. Find the column with primary set to true.



def get_primary_column_id(columns):
for column in columns:
if (column.primary):
return column.id


Grab the row Ids and append all the info to the info_array.



# get row ids
for row in full_sheet.rows:
info_array.append('sheet_id': sheet.id,
'row_id': row.id,
'primary_column_id': primary_column_id)


Here's the Gist.






share|improve this answer

























  • Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

    – AME
    Nov 16 '18 at 3:44











  • sorry about that. updated my answer with the code for get_primary_column_id()

    – stmcallister
    Nov 16 '18 at 7:25











  • A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

    – AME
    Nov 20 '18 at 4:28











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312439%2floop-through-sheets-and-append-columns%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














I'm not sure about pandas, but I can help you get the information into a python array.



Using the Smartsheet Python SDK you'll want to first install the SDK, then import smartsheet.



Next, initialize a Smartsheet object with your access token like so



ss_client = smartsheet.Smartsheet(SMARTSHEET_ACCESS_TOKEN)


Grab your Workspace



workplace = ss_client.Workspaces.get_workspace(workplace_id)


Grab the sheets from the Workspace



wp_sheets = workplace.sheets


Initialize the array you're creating



info_array = 


Loop over the sheets from the Workspace object. These sheet objects only have a few fields to identify the sheet, so you'll need to use the sheet.id to get the full sheet from the Smartsheet API.



# loop through sheets 
for sheet in wp_sheets:
# get sheet
full_sheet = ss_client.Sheets.get_sheet(sheet.id)


Grab the primary column for the sheet



# get the primary column
primary_column_id = get_primary_column_id(full_sheet.columns)


The get_primary_column_id() function would look like this. The column objects have a boolean field for primary. Find the column with primary set to true.



def get_primary_column_id(columns):
for column in columns:
if (column.primary):
return column.id


Grab the row Ids and append all the info to the info_array.



# get row ids
for row in full_sheet.rows:
info_array.append('sheet_id': sheet.id,
'row_id': row.id,
'primary_column_id': primary_column_id)


Here's the Gist.






share|improve this answer

























  • Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

    – AME
    Nov 16 '18 at 3:44











  • sorry about that. updated my answer with the code for get_primary_column_id()

    – stmcallister
    Nov 16 '18 at 7:25











  • A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

    – AME
    Nov 20 '18 at 4:28
















3














I'm not sure about pandas, but I can help you get the information into a python array.



Using the Smartsheet Python SDK you'll want to first install the SDK, then import smartsheet.



Next, initialize a Smartsheet object with your access token like so



ss_client = smartsheet.Smartsheet(SMARTSHEET_ACCESS_TOKEN)


Grab your Workspace



workplace = ss_client.Workspaces.get_workspace(workplace_id)


Grab the sheets from the Workspace



wp_sheets = workplace.sheets


Initialize the array you're creating



info_array = 


Loop over the sheets from the Workspace object. These sheet objects only have a few fields to identify the sheet, so you'll need to use the sheet.id to get the full sheet from the Smartsheet API.



# loop through sheets 
for sheet in wp_sheets:
# get sheet
full_sheet = ss_client.Sheets.get_sheet(sheet.id)


Grab the primary column for the sheet



# get the primary column
primary_column_id = get_primary_column_id(full_sheet.columns)


The get_primary_column_id() function would look like this. The column objects have a boolean field for primary. Find the column with primary set to true.



def get_primary_column_id(columns):
for column in columns:
if (column.primary):
return column.id


Grab the row Ids and append all the info to the info_array.



# get row ids
for row in full_sheet.rows:
info_array.append('sheet_id': sheet.id,
'row_id': row.id,
'primary_column_id': primary_column_id)


Here's the Gist.






share|improve this answer

























  • Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

    – AME
    Nov 16 '18 at 3:44











  • sorry about that. updated my answer with the code for get_primary_column_id()

    – stmcallister
    Nov 16 '18 at 7:25











  • A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

    – AME
    Nov 20 '18 at 4:28














3












3








3







I'm not sure about pandas, but I can help you get the information into a python array.



Using the Smartsheet Python SDK you'll want to first install the SDK, then import smartsheet.



Next, initialize a Smartsheet object with your access token like so



ss_client = smartsheet.Smartsheet(SMARTSHEET_ACCESS_TOKEN)


Grab your Workspace



workplace = ss_client.Workspaces.get_workspace(workplace_id)


Grab the sheets from the Workspace



wp_sheets = workplace.sheets


Initialize the array you're creating



info_array = 


Loop over the sheets from the Workspace object. These sheet objects only have a few fields to identify the sheet, so you'll need to use the sheet.id to get the full sheet from the Smartsheet API.



# loop through sheets 
for sheet in wp_sheets:
# get sheet
full_sheet = ss_client.Sheets.get_sheet(sheet.id)


Grab the primary column for the sheet



# get the primary column
primary_column_id = get_primary_column_id(full_sheet.columns)


The get_primary_column_id() function would look like this. The column objects have a boolean field for primary. Find the column with primary set to true.



def get_primary_column_id(columns):
for column in columns:
if (column.primary):
return column.id


Grab the row Ids and append all the info to the info_array.



# get row ids
for row in full_sheet.rows:
info_array.append('sheet_id': sheet.id,
'row_id': row.id,
'primary_column_id': primary_column_id)


Here's the Gist.






share|improve this answer















I'm not sure about pandas, but I can help you get the information into a python array.



Using the Smartsheet Python SDK you'll want to first install the SDK, then import smartsheet.



Next, initialize a Smartsheet object with your access token like so



ss_client = smartsheet.Smartsheet(SMARTSHEET_ACCESS_TOKEN)


Grab your Workspace



workplace = ss_client.Workspaces.get_workspace(workplace_id)


Grab the sheets from the Workspace



wp_sheets = workplace.sheets


Initialize the array you're creating



info_array = 


Loop over the sheets from the Workspace object. These sheet objects only have a few fields to identify the sheet, so you'll need to use the sheet.id to get the full sheet from the Smartsheet API.



# loop through sheets 
for sheet in wp_sheets:
# get sheet
full_sheet = ss_client.Sheets.get_sheet(sheet.id)


Grab the primary column for the sheet



# get the primary column
primary_column_id = get_primary_column_id(full_sheet.columns)


The get_primary_column_id() function would look like this. The column objects have a boolean field for primary. Find the column with primary set to true.



def get_primary_column_id(columns):
for column in columns:
if (column.primary):
return column.id


Grab the row Ids and append all the info to the info_array.



# get row ids
for row in full_sheet.rows:
info_array.append('sheet_id': sheet.id,
'row_id': row.id,
'primary_column_id': primary_column_id)


Here's the Gist.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 7:24

























answered Nov 16 '18 at 2:05









stmcallisterstmcallister

1,3871815




1,3871815












  • Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

    – AME
    Nov 16 '18 at 3:44











  • sorry about that. updated my answer with the code for get_primary_column_id()

    – stmcallister
    Nov 16 '18 at 7:25











  • A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

    – AME
    Nov 20 '18 at 4:28


















  • Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

    – AME
    Nov 16 '18 at 3:44











  • sorry about that. updated my answer with the code for get_primary_column_id()

    – stmcallister
    Nov 16 '18 at 7:25











  • A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

    – AME
    Nov 20 '18 at 4:28

















Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

– AME
Nov 16 '18 at 3:44





Thanks! How can I get the primary column id from 100+ sheets? I believe the column Id varies from sheet to sheet. Can I look up column id by column name?

– AME
Nov 16 '18 at 3:44













sorry about that. updated my answer with the code for get_primary_column_id()

– stmcallister
Nov 16 '18 at 7:25





sorry about that. updated my answer with the code for get_primary_column_id()

– stmcallister
Nov 16 '18 at 7:25













A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

– AME
Nov 20 '18 at 4:28






A strange thing happened when I modified this code to perform a specific action. My goal was to move all rows in sheets within the test workforce to a target sheet. I used this code to narrow down the list of rows that I needed to move. However, when I ran the code, code performed the desired action but in a different (production) workspace!

– AME
Nov 20 '18 at 4:28




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312439%2floop-through-sheets-and-append-columns%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3