Search code examples
pythonpandasdataframegoogle-sheetsgspread

How i can specifiy the datatype when import google sheet with gspread_pandas?


I have a google sheet with a fixed number of columns and variabile numer of rows that are the value of environment sensors. the sheet format is Data table

im able to import it in a data frame with gspread-pandas

s=Spread(spread=gsheet_id,config=gspread_pandas.conf.get_config(conf_dir=conf_path,file_name=service_file))

pd.DataFrame=s.sheet_to_df(sheet='06-2020')

the problem is the type of Dataframe Series, each series has a dtype('0').

>>pd.DataFrame['T_PREP_[°C]'].dtypes
dtype('O')

To import a google sheet with correct type,i need to specify the data of each columns or i need to convert with pandas?

thanks in advance!


Solution

  • I'm the author of gspread-pandas. Unfortunately, there's no way to do so right now. I have an issue out there for a while about it, but haven't had time to work on it. Any PRs welcome: https://github.com/aiguofer/gspread-pandas/issues/18.

    What I've done in the past is to manually convert columns using something like:

    pd.DataFrame['T_PREP_[°C]'] = pd.DataFrame['T_PREP_[°C]'].astype(<conversion_type>)