Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data gets interpreted even when using dtype=str #42

Closed
MrBeardedGuy opened this issue Dec 18, 2021 · 1 comment
Closed

Data gets interpreted even when using dtype=str #42

MrBeardedGuy opened this issue Dec 18, 2021 · 1 comment

Comments

@MrBeardedGuy
Copy link

I'm using gspread_dataframe to import data from Google Sheets. I'd like to force all imported data to strings independently of the cell type used in the worksheet.

The documentation mentions I can use all options supported by the Pandas text parsing readers. In theory dtype=str or dtype=object should force all values to be preserved without interpreting them. Somehow this is not true, not sure if it's a bug or I'm doing something wrong.

In the scenario below the imported dataframe has decimals dropped due to the fact that all Amounts are in number format in the worksheet. If I change the worksheet type to 'string' the desired outcome is correct, but I'm trying to avoid tweaking the file before importing the data.

import gspread
import gspread_dataframe as gsframe

gsframe.get_as_dataframe(
    worksheet=sheet, 
    header=0, 
    dtype=str, 
    usecols=cols, 
    skiprows=row_offset,
    skip_blank_lines=True).dropna(axis = 0, how = 'all').fillna('')
   Worksheet	      Imported Dataframe	
string	numbers		string	string
				
Name	Amount		Name	Amount
A	-25.00		A	   -25
B	-63.00		B	   -63
C	 20.00		C	    20
D	-10.00		D	   -10
				
  		                     ▲ dropped decimals		

Expected outcome

   Worksheet	      Imported Dataframe	
string	numbers		string	string
				
Name	Amount		Name	Amount
A	-25.00		A	-25.00
B	-63.00		B	-63.00
C	 20.00		C	 20.00
D	-10.00		D	-10.00			
@MrBeardedGuy MrBeardedGuy changed the title Data gets interpreted anyways even when using dtype=str Data gets interpreted even when using dtype=str Dec 18, 2021
@MrBeardedGuy
Copy link
Author

Closing this one. I've found the issue. The interpretation happens once the data gets added back to the sheet. New rows in Google Sheets get created with type automatic by default. That's what'c causing the decimals inconsistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant