I am a newbie working with Smartsheet, I am trying to access the values of columns and store them in a list, and I am able to access the values by the index. In my use case, people can delete random columns from the smartsheet and that can cause my index numbering affected while reading the data. For Example - My smartsheet looks like below:
Vin | Owner | Use | Location
123 abc test CA
456 xyz prod TX
The code I used so far to access the data is:
import smartsheet
from simple_smartsheet import Smartsheet
from simple_smartsheet.models import Sheet, Column, Row, Cell, ColumnType
from pprint import pprint
import pandas as pd
import re
import sasl
import json
from fastparquet import write
# from influxdb import InfluxDBClient
import thrift_sasl
import prestodb
import s3fs
import boto3
from pyhive import hive
smartsheet = smartsheet.Smartsheet('adjgdjcdjchbdclkcn')
# Get current user
#user_profile = smartsheet.Users.get_current_user()
# Get all columns.
MySheet = smartsheet.Sheets.get_sheet(1234567891234567)
Vin = []
Owner = []
Use = []
Location = []
def Data():
for RowIndex in range(0, len(MySheet.rows)):
Vin.append(MySheet.rows[RowIndex].cells[2].display_value)
Use.append(MySheet.rows[RowIndex].cells[3].display_value)
Owner.append(MySheet.rows[RowIndex].cells[4].display_value)
Location.append(MySheet.rows[RowIndex].cells[5].display_value)
print(Vin)
print(Use)
Print(Owner)
Print(Location)
Result I want is (Using the column name instead of Index):
Vin = [123, 456]
Owner = [abc, xyz]
Use = [test, prod]
Location = [CA, TX]
Now Instead of accessing the values by index, how can I append the values in a list using column name instead? Any help or lead is much appreciated. Thank You in advance!