I am trying to export a python pandas dataframe into google sheets but the values that appear in the cells all start with an apostrophe ('). Is there a way for me to format the values so the output would be a normal number without manually formatting the numbers on google sheets? I am using df2gspread to upload my data to google sheets. I'm assuming this is because the numbers are being read as str, but I did pd.to_numeric to all numerical values so I thought it would have resolved but no. Any ideas on how I should approach/fix this?
import gspread
from df2gspread import df2gspread as d2g
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
import numpy as np
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
#service_account from Google API.
credentials = ServiceAccountCredentials.from_json_keyfile_name(
"service_account.json", scope)
gc = gspread.authorize(credentials)
wks = gc.open("Two").sheet1
data = wks.get_all_values()
headers = data.pop(0)
ssid = 'insert-ssid'
wks_name = 'Transform'
wks_name1 = 'Summary'
cell_of_start_df = 'B2'
pd.set_option('display.max_rows', 300)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
df = pd.DataFrame(data, columns=headers)
df2 = ...
d2g.upload(df,
ssid,
wks_name,
credentials = credentials,
col_names = True,
row_names = True,
start_cell = cell_of_start_df,
clean = True)
d2g.upload(df2,
ssid,
wks_name1,
credentials = credentials,
col_names = True,
row_names = True,
start_cell = cell_of_start_df,
clean = True)
I get AttributeError: 'str' object has no attribute 'values_update' when using the update method
values = [df.columns.values.tolist()]
values.extend(df.values.tolist())
wks_name.values_update('Transform', params={'valueInputOption': 'USER_ENTERED'}, body={'values': values})
values2 = [df2.columns.values.tolist()]
values2.extend(df2.values2.tolist())
wks_name1.values_update('Summary', params={'valueInputOption': 'USER_ENTERED'}, body={'values': values})
My error occurs in line wks_name.values_update saying 'str' has no attribute "values update". I have tried changing possible variables but it seems like I'm missing something.