I need to push 1.18 MB or approximately 10,000 rows of data from a csv file residing on my server to a Google Sheet for Tableau to read.
The data is coming in from Google DFP into a csv document. I have been using the gspread library to update google sheets with the csv data before, however with 10,000 records and the ~30 seconds to post per record this approach will not be valid.
Is there a faster way to copy the contents of a csv/txt file to a google spreadsheet than by using the gspread library? Preferably with Python.
Update: I'm trying this approach of bulk updating the cells.
raw_dfp = pd.read_csv('live_dfp_UTF.csv', error_bad_lines=False)
sample5 = raw_dfp.iloc[:3, :]
rows, col = sample5.shape
doc.resize(1, 7)
doc.clear()
doc.resize(rows + 1, col)
column_names = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
cell_range = 'A1:' + column_names[col] + str(rows)
cells = doc.range(cell_range)
# To use this next line??
# flattened_data = np.flatten(sample5)
for x in range(rows):
cells[x].value = sample5[x].decode('utf-8')
doc.update_cells(cells)
cells
is a 1D structure, while the spreadsheet is 2D. So, you first need to flatten the spreadsheet data to 1D and then run thefor x in range(rows)
. It looks likecells[x].value = sample5[x].decode('utf-8')
should becells[x].value = flattened_data[x].decode('utf-8')
. – roganjoshflattened_data = sample5.flatten()
, I missed that. You need to get a 2D numpy array out of your DataFrame first. My initial answer on the other question assumed Python lists. It might be that you need to callas_matrix
on the DataFrame, then flatten it. Sorry, not hugely familiar with numpy/pandas. – roganjosh