Git Product home page Git Product logo

drive_dataframe_uploader's Introduction

drive_dataframe_uploader

Package downloads, appends, duplicates from template, or replaces a Google Sheet with a pandas dataframe. A dictionary is used to determine the sheet(s) to work on.

How To Use 1. Install the module using pip:
pip install drive-dataframe-uploader
  1. Import the module & instantiate the GoogleDrivePython class:

    import drive_dataframe_uploader as ddu
    dl = ddu.DataFrameLoader()
  2. Store the full path to your google service account in a variable:

    service_account = '/Users/luyanda.dhlamini/Projects/client_secret.json'
  3. Create a dictionary with the Google Spreadsheet sheet name & doc key to work on:

    # Dictionary format: { sheet_name_string : { 'doc_key' : spread_sheet_id_string } }
    sheet_name = 'Sheet1'   # This is the name of the spreadsheet sheet to work on.
    doc_key = '1ZqLUWuANFa8rCRF2tpIgCNl-IWsmw2MKWxPVpmfUM0s'    # The document id found in the spreadsheet's link.
    data_dictionary = { sheet_name : { 'doc_key' : doc_key } }
    
  4. Use the get_existing() function to download the data from a Spreadsheet into a pandas DataFrame:

    # Create & save a text file into the local directory
    existing_data_dictionary = dl.get_existing( data_dictionary = data_dictionary, service_account_json_path = service_account)
    existing_df = existing_data_dictionary[sheet_name]['dataframe']
    print( existing_df.head() )
    
    # Change the first value of the downloaded dataframe.
    existing_df.at[ 0, existing_df.columns[0] ] = 'Changed'
    
    # Store the dictionary in the data_dictionary
    data_dictionary[sheet_name]['dataframe'] = existing_df
    
    # Print the data_dictionary to assess if the dataframe has been stores in the data_dictionary
    print( data_dictionary )
  5. Use the update_data_overwrite() function to upload & overwrite the data in a Spreadsheet using the data_dictionary created above. All tabular data contained in the target sheet is deleted:

    # Pass in the data_dictionary created above to overwrite data in the existing Sheet1.
    # If the passed in sheet cannot be found, a new sheet is created.
    data_dictionary2 = dl.update_data_overwrite( data_dictionary = data_dictionary, service_account_json_path = service_account) 
    
  6. Use the update_data_append() function to upload & append to the data in a Spreadsheet using the data_dictionary created above. All tabular data contained in the target sheet is first downloaded, empty rows & columns are removed. New data is concated vertically to existing data:

    # Pass in the data_dictionary created above to append to data in the existing Sheet1.
    # If the passed in sheet cannot be found, a new sheet is created.
    data_dictionary3 = dl.update_data_append( data_dictionary = data_dictionary, service_account_json_path = service_account)
Package Dependencies

drive_dataframe_uploader's People

Contributors

luyandadhlamini avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.