Recently I have done lot of data analysis in Python (more details about this in another post) and have started to like Pandas a lot. The other day I had to process some data from a Google Sheet and was wondering whether I could read the data as a Pandas DataFrame and after a quick search found the
gspread package and within a few lines of code I was able to read data from Google Sheet into a Pandas DataFrame.
I thought of sharing the code here so that it would be helpful for others and I would also know whether to search for it when I need it the next time 🙂
So here we go, this is all we need. Of course you need to install the
I tried your approach and found that the pandas df was created from the google sheet, but the columns were out of order. Do you know how to fix this?
They come in alphabetized (let’s say A,B,C) and you need to reorder them how you want by:
df = df[[“column_C”,”column_A”,”column_B”]]
gspread has no attribute ‘login’?