You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I relatively frequently will be trying to use get_as_dataframe to pull in values from a gsheet, do some operation to them ad then only update a single column in the original gsheet with set_with_dataframe. However, I always get a value error when I do so, as in the below stacktrace:
Traceback (most recent call last):
File "<string>", line 19, in __PYTHON_EL_eval
File "~/Documents/Phon_Utils/scratch.py", line 16, in <module>
File "~/Documents/Phon_Utils/venv/lib/python3.11/site-packages/gspread_dataframe.py", line 262, in set_with_dataframe
y, x = dataframe.shape
^^^^
ValueError: not enough values to unpack (expected 2, got 1)
Would it be possible to update the function so that it can also accept dataframes that are only a single column wide as input?
The text was updated successfully, but these errors were encountered:
@zwhitney-nc Sorry for the delay in responding! You are not passing a DataFrame to set_as_dataframe -- you are passing a Series representing a single column. To update just one column of the Google worksheet, using just one column from your DataFrame, you want to perform the following steps:
Create a simple DataFrame with just the column you select: pandas.DataFrame(my_dataframe[my_column]). That's it -- the single column Series has the same index as the original DataFrame, and it keeps its name (header). The new DataFrame will keep that index and column name (header).
Know which column on the Google worksheet corresponds to the column to update. This is a numeric value, starting with 1 for the leftmost column (A). B=2, C=3, etc.
When you call set_with_dataframe, pass the new one-column DataFrame you created, and also col={the_column_number_you_determined} as a keyword argument.
The above should update just that single column in the worksheet. Let me know if it works for you.
robin900
changed the title
Value Error when trying to set a single column
Advice to update just one column of a DataFrame in a worksheet (was: ValueError when trying to set a single column)
May 24, 2024
I relatively frequently will be trying to use get_as_dataframe to pull in values from a gsheet, do some operation to them ad then only update a single column in the original gsheet with set_with_dataframe. However, I always get a value error when I do so, as in the below stacktrace:
Would it be possible to update the function so that it can also accept dataframes that are only a single column wide as input?
The text was updated successfully, but these errors were encountered: