Skip to content

Commit

Permalink
feature: Allow us to set how uploaded data should be interpreted. by @…
Browse files Browse the repository at this point in the history
  • Loading branch information
uehara1414 committed Dec 31, 2019
1 parent f14da35 commit 0402aac
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions df2gspread/df2gspread.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def upload(df, gfile="/New Spreadsheet", wks_name=None,
col_names=True, row_names=True, clean=True, credentials=None,
start_cell = 'A1', df_size = False, new_sheet_dimensions = (1000,100)):
start_cell = 'A1', df_size = False, new_sheet_dimensions = (1000,100), value_input_opt='RAW'):
'''
Upload given Pandas DataFrame to Google Drive and returns
gspread Worksheet object
Expand All @@ -46,6 +46,7 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None,
the sheet larger.
-If False and dataframe is smaller than existing sheet, does not resize.
:param new_sheet_dimensions: tuple of (row, cols) for size of a new sheet
:param value_input_opt: Determines how input data should be interpreted.
:type df: class 'pandas.core.frame.DataFrame'
:type gfile: str
:type wks_name: str
Expand All @@ -56,6 +57,7 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None,
:type start_cell: str
:type df_size: bool
:type new_sheet_dimensions: tuple
:type value_input_opt: str
:returns: gspread Worksheet
:rtype: class 'gspread.models.Worksheet'
Expand Down Expand Up @@ -123,15 +125,15 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None,
cell_list = wks.range('%s%s:%s%s' % (first_col, start_row, last_col, start_row))
for idx, cell in enumerate(cell_list):
cell.value = df.columns.astype(str)[idx]
wks.update_cells(cell_list)
wks.update_cells(cell_list, value_input_option=value_input_opt)

# Addition of row names
if row_names:
cell_list = wks.range('%s%s:%s%d' % (
start_col, first_row, start_col, last_idx))
for idx, cell in enumerate(cell_list):
cell.value = df.index.astype(str)[idx]
wks.update_cells(cell_list)
wks.update_cells(cell_list, value_input_option=value_input_opt)


# convert df values to string
Expand All @@ -144,7 +146,7 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None,
if not pd.isnull(df[col][idx]):
cell_list[i + j * len(df.columns.values)].value = df[col][idx]

wks.update_cells(cell_list)
wks.update_cells(cell_list, value_input_option=value_input_opt)
return wks

def clean_worksheet(wks, gfile_id, wks_name, credentials):
Expand Down

0 comments on commit 0402aac

Please sign in to comment.