-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The importData function is used to import specific data from a Google Sheet. It allows you to retrieve data from a given worksheet and column(s), while also specifying the range of rows (first and last) to import. The data retrieved can be automatically converted into numerical format for further processing.
def importData(fileName, sheetName, numCol, firstRow=1, lastRow=None)
-
fileName(str):
The name of the Google Sheet file from which the data will be imported. -
sheetName(str):
The name of the worksheet within the Google Sheet where the data is located. -
numCol(int or list):
The column number(s) to import data from. This can be a single integer for one column or a list of integers for multiple columns. -
firstRow(int, optional):
The number of the first row to import, using 1-based indexing (default is 1, meaning the first row). The data starts from this row. -
lastRow(int, optional):
The number of the last row to import, using 1-based indexing. If not specified (None), the function will import all rows until the end of the column(s).
- list:
Returns a list (or list of lists, if multiple columns are specified) containing the data from the specified columns and row range. The data is automatically converted to numerical format where applicable.
To import data from column 3 of the worksheet "Sheet1", starting from row 2 until the last row:
data = importData("My Google Sheet", "Sheet1", 3, firstRow=2)
print(data)This imports data from column 3, skipping the first row (perhaps a header row), and retrieves all the remaining rows.
To import data from columns 1 and 4 of the worksheet "Data", between rows 5 and 20:
data = importData("Experiment Results", "Data", [1, 4], firstRow=5, lastRow=20)
print(data)This retrieves data from columns 1 and 4, starting at row 5 and ending at row 20, for both columns.
To import all rows from column 2 starting from row 1:
data = importData("Sales Data", "Q1", 2)
print(data)This retrieves all data from column 2, starting at row 1, until the end of the sheet.
To import data from column 2 between rows 10 and 50:
data = importData("Attendance", "January", 2, firstRow=10, lastRow=50)
print(data)This imports data from column 2, retrieving rows 10 through 50.