Google Sheets and Python - Tutorial

Поділитися
Вставка
  • Опубліковано 5 вер 2024
  • Learn how to use Google Sheets API in Python. We are using the gspread module for this. It's super simple to setup a project, and then access and modify our spreadsheet with a Python script. Google Sheets can be pretty powerful and used as a backend to store some data for your web applications.
    ~~~~~~~~~~~~~~ GREAT PLUGINS FOR YOUR CODE EDITOR ~~~~~~~~~~~~~~
    ✅ Write cleaner code with Sourcery: sourcery.ai/?u... *
    📚 Get my FREE NumPy Handbook:
    www.python-eng...
    📓 Notebooks available on Patreon:
    / patrickloeber
    ⭐ Join Our Discord : / discord
    If you enjoyed this video, please subscribe to the channel!
    The code can be found here:
    github.com/pat...
    Check out gspread documentation here: gspread.readth...
    You can find me here:
    Website: www.python-eng...
    Twitter: / patloeber
    GitHub: github.com/pat...
    #Python
    ----------------------------------------------------------------------------------------------------------
    * This is a sponsored link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏

КОМЕНТАРІ • 142

  • @muhammadusmannaeem609
    @muhammadusmannaeem609 3 роки тому +11

    I watched many videos, they all required HELL long process for enabling reading and writing. This is the best one so far that works even a year later. Hats off to you.

    • @patloeber
      @patloeber  3 роки тому +1

      thanks, glad its helpful!

  • @AndreasDeloitte
    @AndreasDeloitte 3 роки тому +2

    explained in a simple fast effective way.
    You are the number one .
    I see 20 others tutorials without doing anything
    Thanks

  • @imdadood5705
    @imdadood5705 2 роки тому +1

    Finally, a video without importing hundreds of other libraries. Awesome! Worked like charm. Want to experiment this further and must see if I can incorporate this to my day to day work. Thank you, Patrik!

  • @bananvital
    @bananvital 2 роки тому

    I’m really grateful for this video. I’d watched a dozen of videos before found your content. Really appreciate it, wish you the best of luck 🤞

  • @zohan6390
    @zohan6390 3 роки тому

    Spend so many times watching videos and yours is the most clearest one. Thank you!

  • @norton_vanz
    @norton_vanz Рік тому

    Clearly explained, worked like a charm! Congrats, Patrick!

  • @samgreen-g5d
    @samgreen-g5d Місяць тому

    Really good explained.

  • @ShashankData
    @ShashankData 3 роки тому

    Thank you! very clear and easy to understand, complete lifesaver

  • @buredabby
    @buredabby 2 роки тому +1

    Brilliantly done, going through examples helps a lot!

  • @royteicher
    @royteicher 3 роки тому +6

    Hey Python Engineer!
    First of all - thanks a lot. This tutorial has been very helpful for me and I enjoy the way you pass your knowledge.
    I have a problem that I couldn't find the answer to on the gspread documentation, so I'd love it if you could find the time to answer:
    My problem is - running my script on my sheet cancels all existing formulas in the sheet.
    The script loops over rows, and depending on a certain condition, It uses the update_cell function to update certain cells' values, one cell at a time.
    I've investigated and found there's the parameter value_input_option - which is not a part of the function "update_cell".
    I just want to run my script and let the whole GS formulas remain (e.g. an Index row with the formula =a1+1 -> the formula will be deleted and the value will stay the same).
    I'm writing this comment after spending hours online but couldn't find a solution.
    Thanks in advance,
    Roy

  • @networkjag
    @networkjag 3 роки тому

    You are the best.. clear explanation of the concepts and very easy to follow along...

  • @arshabdulmajeed2116
    @arshabdulmajeed2116 3 роки тому

    easily explained thanks bro

  • @rajjohri8547
    @rajjohri8547 3 роки тому

    this is an awesome video...I was watching other videos and getting stuck by an extra difficult way of accessing google sheets!

    • @patloeber
      @patloeber  3 роки тому

      I'm glad it's helpful :)

  • @rutanshudesai
    @rutanshudesai Рік тому

    Great tutorial, thank you!

  • @mygcoder
    @mygcoder 2 роки тому

    First of all thanks for your great video. Could you suggest me a tutorial how to check google forms every minute and send auto emails to new entries.

  • @mohamedsuhailirfankhazi6628
    @mohamedsuhailirfankhazi6628 3 роки тому

    Very good tutorial. Simple to follow and cleared a lot of my doubts! Awesome stuff.

  • @clashclan7549
    @clashclan7549 2 роки тому

    Appreciate your help 🙏

  • @veyselaksin
    @veyselaksin 2 роки тому

    Thanks this tutorial bro. Can we send multiple data from python to google sheets?

  • @ucsdncmir
    @ucsdncmir 3 роки тому

    Love your tutorial. Very easy to follow. Thanks

  • @gabrielbiacchi6169
    @gabrielbiacchi6169 2 місяці тому

    Thank you so much!!

  • @reigner41
    @reigner41 3 роки тому

    this helped me mate thank you

  • @ninadalgotester4136
    @ninadalgotester4136 3 роки тому

    thanks a lot...really very useful video

  • @tejamarneni
    @tejamarneni 4 роки тому +1

    Your Videos are amazing. Keep up the good work.

  • @mondomeccano
    @mondomeccano 3 роки тому

    Excellent video. Thank you - I struggled without this.

  • @akhilkn225
    @akhilkn225 4 роки тому +1

    Very useful video. I want to replace the whole old df with new df in sheets with this method. Dfs contain 1500 columns.

  • @bensaxon3829
    @bensaxon3829 4 роки тому

    Thanks very much. Spent a long time trying to figure this out

    • @patloeber
      @patloeber  4 роки тому

      I'm glad it was helpful :)

  • @sk1lz2l1fe
    @sk1lz2l1fe 2 роки тому

    Thanks so much for your guide!
    Is there a way to remove the "['']" text?

  • @Ivgi-j1w
    @Ivgi-j1w 3 роки тому

    Congratulations I subscribed to your channel

  • @krevedko_krevedkin
    @krevedko_krevedkin 3 роки тому

    Thanks a lot, this was very useful for me. Im noob in Python, but i try to create application which uses sheets API

  • @ahmedshiref4935
    @ahmedshiref4935 3 роки тому

    Thank you.

  • @binduvadlamudi9233
    @binduvadlamudi9233 2 роки тому

    Excellent 👌

  • @angshumanmukherjee3021
    @angshumanmukherjee3021 2 роки тому

    It is a great video. Thank you! if please share a code to save data of panda data frame data into a google sheet.

  • @EUU100
    @EUU100 3 роки тому

    thank you for your time and clear explanation, is there a way we can make the google sheet receive the data every 24hours?

  • @obimichelle2252
    @obimichelle2252 2 роки тому

    thanks very helpfull

  • @pipeliner8969
    @pipeliner8969 4 роки тому

    Subscribed! Please make more google apps and python videos! You have good content and are explaining pretty well! Or maybe sync Libre Office Calc with Sheets.

    • @patloeber
      @patloeber  4 роки тому

      Thanks for the tips and thanks for subscribing!

  • @hansdecorti7474
    @hansdecorti7474 3 роки тому

    very useful! I am just starting out with Python and GoogleSheets, and am looking to read QR-codes, and append the information scanned + time/date for an attendance system.
    Love the idea of the data in the cloud, and my task is to get a foolproof input system maybe a raspberry pi headless with a barcode scanner....
    Subscribed!
    cheers und danke

    • @patloeber
      @patloeber  3 роки тому

      Sounds like a nice project :)

  • @mohamed-su3tq
    @mohamed-su3tq 3 роки тому

    great job . but how i make search operation ?

  • @SandeepInnovation
    @SandeepInnovation 3 роки тому

    very useful video.

  • @premchand5411
    @premchand5411 3 роки тому +1

    module 'gspread' has no attribute 'service_account'
    I am getting this error :(

  • @firstnotefoundation
    @firstnotefoundation 3 роки тому

    Thank you Python Engineer for this to-the-point and well thought-out video. Subscribed :)

    • @patloeber
      @patloeber  3 роки тому

      Thanks 😊 glad you like it :)

    • @firstnotefoundation
      @firstnotefoundation 3 роки тому

      Hi @@patloeber,
      Can you please help me with the following issue? I’m completely new to Python. I was facing difficulty with one script I had written:
      ==================================
      import requests
      from bs4 import BeautifulSoup
      # Opening NSE website to scrape Free Float Market Cap(Crs) value
      url = "www1.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=ACC&illiquid=0&smeFlag=0&itpFlag=0"
      headers = {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'GET',
      'Access-Control-Allow-Headers': 'Content-Type',
      'Access-Control-Max-Age': '3600',
      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.114 Safari/537.36'
      }
      response = requests.get(url, headers=headers)
      soup = BeautifulSoup(response.content, 'html.parser')
      floatValue = soup.find(id="ffmid")
      print(floatValue)
      print(floatValue.string)
      ==================================
      Even though the Free Float Market Cap(Crs) value is 14,229.25 on the website, I’m getting the following output in Sublime Text:
      --
      --
      Why is it showing as -- instead of the value? Can’t figure out the error.

  • @JoaoNeto-up8zi
    @JoaoNeto-up8zi 3 роки тому

    Huge like, share and thumbsup, your guide is the perfect introduction on UA-cam and that's final.
    BTW, is there a way to reference columns by their letter instead of number?

    • @patloeber
      @patloeber  3 роки тому +1

      Thanks so much! Yes absolutely, e.g. worksheet.get('A1')

    • @JoaoNeto-up8zi
      @JoaoNeto-up8zi 3 роки тому

      @@patloeber Cool! Also, why do the script stops loading the credentials once I put them in another folder? Shouldn't the files being in the same folder be enough?

  • @vishnunandakumar8524
    @vishnunandakumar8524 3 роки тому

    How can we write a python script to push data from Excel to Google sheets?

  • @Richard.bassan
    @Richard.bassan 3 роки тому

    Could you please teach us how to do update google sheets through Excel? Thank you!

  • @nicolaswirtz6952
    @nicolaswirtz6952 3 роки тому

    Super informative and thank you for keeping this video concise! I was wondering, is it possible to do an append style command for a row but with specified columns? For example, using the same append function that you used, but the table is in columns J, K, and L. Thank you!

    • @patloeber
      @patloeber  3 роки тому +1

      Yep should be possible. I recommend to have a look into the official docs to find this method

    • @ninadalgotester4136
      @ninadalgotester4136 3 роки тому

      hi Nicholas...same issue i got n went thru official docs as well as searched online but no proper solution (i used table_range but after appending few rows in my desired column it switches back to 1st column) ....please let know if you were able to find the way..thanks

  • @Jeevaji14
    @Jeevaji14 3 роки тому

    Super video

  • @panyoy
    @panyoy 4 роки тому +1

    Thank you!

  • @efcdatasupport6375
    @efcdatasupport6375 3 роки тому

    How we can connect sql server table to google sheet

  • @ApicProductions
    @ApicProductions 3 роки тому

    Thank you! This video helped a lot.

    • @patloeber
      @patloeber  3 роки тому

      That's nice to hear :)

  • @danielegrotti5231
    @danielegrotti5231 3 роки тому

    you're amazing man!! Thank yuo so much!

  • @chekristinemaehernandez5192
    @chekristinemaehernandez5192 3 роки тому +1

    Hello. It says that "no module named 'gspread', what will I do?

  • @flamboyantperson5936
    @flamboyantperson5936 4 роки тому

    Please make videos more frequently

  • @talha_anwar
    @talha_anwar 3 роки тому

    i dont have create key option

  • @kwamenadadson
    @kwamenadadson 4 роки тому

    Thank you very much

  • @sky-right
    @sky-right 3 роки тому

    Great! Thanks!

  • @JosePerez-qt8cf
    @JosePerez-qt8cf 4 роки тому

    Thanks a lot for the very useful information!!!! But I have a question do I need to pay for the usage of the api than Google offers me or is it free?

    • @patloeber
      @patloeber  4 роки тому

      They offer a generous free limit (I think it's 10.000 API calls per day)

  • @tazulislam2698
    @tazulislam2698 2 роки тому

    how to append multiple row?

  • @KraSatira
    @KraSatira 4 роки тому

    Very very useful

  • @pleabargain
    @pleabargain 4 роки тому

    Very useful! Could you do same tut using google colab?

    • @patloeber
      @patloeber  4 роки тому +1

      Thanks! I will have a look at that

  • @duypham5955
    @duypham5955 3 роки тому

    How to integrate python and google sheet android mobile ( mobile vsmart )

  • @ordinaryuser2954
    @ordinaryuser2954 Рік тому

    love you

  • @preciseair2590
    @preciseair2590 3 роки тому

    how can I CREATE a spreadsheet that doesnt exist yet ? (then fill it with data) the example here uses a spreadsheet 'tutorial' that already exist.

    • @EUU100
      @EUU100 3 роки тому +1

      go to google sheets and create a new spreadsheet manually

  • @duypham5955
    @duypham5955 3 роки тому

    What app it download more

  • @vincentchen2127
    @vincentchen2127 4 роки тому

    is there a way to switch between the sheets in the google sheets (bottom left corner of the google sheets)

    • @patloeber
      @patloeber  4 роки тому

      yes you can access different worksheets like so: sh.get_worksheet(0), or by title: sh.get_worksheet("name")

  • @suchithraab8515
    @suchithraab8515 3 роки тому

    thanks a lot, great information. and i have a doubt please clarify me.
    We all know how is our team page looks in WordPress webpage. My question is, is it possible to update those information from google sheet to WordPress team page and it looks same as our webpage teams page.. If so, please tell me how to do.
    now i got to know how to read data from google sheet using python and then now need to update those data to wordpress team page. how to do please reply me.

    • @patloeber
      @patloeber  3 роки тому

      yes it's possible but I'm not very familiar with Wordpress myself...

  • @user-ho9qj2xu7f
    @user-ho9qj2xu7f 4 роки тому

    Very useful video. This means a lot to me. I couldn’t have done it without you.

    • @patloeber
      @patloeber  4 роки тому

      Thanks! Glad you like it

  • @manishdeswal2368
    @manishdeswal2368 3 роки тому

    awesome!

  • @kyng386
    @kyng386 3 роки тому

    Is it possible to read cell colors?

    • @patloeber
      @patloeber  3 роки тому

      Yes it should be possible to get and set colors

  • @zedkrimo
    @zedkrimo 3 роки тому

    thnk u

  • @priscillamatthews3240
    @priscillamatthews3240 4 роки тому

    I don't know why, but when I'm on the last step of creating the service account for the Google Drive API, the create key is not an option here. What should I do?

    • @joaquinsilvabidart3959
      @joaquinsilvabidart3959 4 роки тому +3

      You can create the service account without the key and then go to edit the new account and add a new key

    • @patloeber
      @patloeber  4 роки тому +1

      yes, thanks for helping out!

  • @azmeux9360
    @azmeux9360 4 роки тому

    I tried doing the pip install on the command prompt for my windows laptop and I keep on getting "'pip' is not recognized as an internal or external command, operable program or batch file." any ideas how I can get this to work?

    • @KraSatira
      @KraSatira 4 роки тому

      Before using pip install you need to go to the folder where you installed python. Otherwise it doesn't work. Doing it is simple, open command prompt and then type "cd [space] [full address where you installed python] pip install what you want to install. I hope I have been useful

    • @patloeber
      @patloeber  4 роки тому

      You have to install pip first...Maybe googling for “install pip on windows” helps :)

    • @MorselHoarder
      @MorselHoarder 4 роки тому +1

      I had this problem too after reinstalling Python 3, which pip supposedly comes installed. To solve it I found a stackoverflow thread titled "pip is not recognized as an internal or external command" (google it). Essentially, the scripts folder which contains pip was not in %PATH%. The first solution in that thread worked for me.

  • @MedialyticsNinja
    @MedialyticsNinja 4 роки тому

    How to append all rows of a dataframe in python, to an existing google sheet? I followed till the process, where you mentioned appending one row. But I want to append all rows of a dataframe. Can you help?

    • @patloeber
      @patloeber  4 роки тому

      use append_rows() which takes a list as input

    • @MedialyticsNinja
      @MedialyticsNinja 4 роки тому

      @@patloeber I used df.values.tolist() to convert df to list. Then iterated all list values using append_rows(). But still no luck. Any idea where I am going wrong?

  • @AndreaBandieraGelatiere
    @AndreaBandieraGelatiere 4 роки тому

    Hi, I receive thi error
    ('invalid_grant: Invalid JWT Signature.', '{"error":"invalid_grant","error_description":"Invalid JWT Signature."}')
    at this line:
    worksheet = sh.sheet1

    • @patloeber
      @patloeber  4 роки тому

      i think your API keys are not valid, or you forgot to share the sheet with the created bot account

  • @vincentchen2127
    @vincentchen2127 4 роки тому

    is that IDLE? im new to this so idk. Im on windows python v3.8.3

    • @patloeber
      @patloeber  4 роки тому

      I'm using VS Code as my editor

  • @kangdu3107
    @kangdu3107 4 роки тому

    when i run it, it got "NameError: name 'credentials' is not defined" does anyone have an idea on why this is happening?

    • @patloeber
      @patloeber  4 роки тому

      Maybe you have a typo ?

  • @duypham5955
    @duypham5955 3 роки тому

    Integrated python and google sheet android mobile please, thank you

  • @raylakurosaki6715
    @raylakurosaki6715 4 роки тому

    How do I select a specific sheet?

    • @patloeber
      @patloeber  4 роки тому +1

      get_worksheet(index)

    • @EUU100
      @EUU100 3 роки тому

      @@patloeber thank you so much for this video, clear and very easy to follow. I also had this question, sorry how do i use the get_worksheet(index) to lets say put a df in sheet2?
      Sorry if my question is unclear i am still new to Python

    • @EUU100
      @EUU100 3 роки тому

      thank you i figured it out

  • @nklong19
    @nklong19 3 роки тому +2

    Thank you so much, very clear and understandable. It's a life-saver for me

  • @Ch-mz2jx
    @Ch-mz2jx 3 роки тому

    Thank you a lot!!

  • @kyozuperso5613
    @kyozuperso5613 3 роки тому

    I don't have the create key button

  • @sirazhov
    @sirazhov 4 роки тому

    Thanks!

  • @ajaybabu8564
    @ajaybabu8564 4 роки тому

    what to write if we have sheet name with spaces?

    • @patloeber
      @patloeber  4 роки тому

      does it not work with spaces? otherwise you can also access the sheet by it's id

  • @Quintren
    @Quintren Рік тому

    Was very useful thank you!