Global AI and Data Science

Global AI & Data Science

Train, tune and distribute models with generative AI and machine learning capabilities


#Artificialintelligence
#Datascience
 View Only
  • 1.  Writing to File using Watson Notebook

    Posted 03/23/20 09:08 AM
    Hello,
    I am new here and to Data Analytics.
    So I have this:
    import csv
    BS=BeautifulSoup(source, 'html5lib')
    infile=open('Toronto Neighborhood', 'w')
    file=csv.writer(infile)
    file.writerow(['PostCode', 'Borough'])
    for heads in BS.find_all ('td'):

    try:
    PostCode=heads.find('p').text
    Borough=heads.find('title')
    except Exception as e:
    PostCode=None
    Borough=None
    print(PostCode,'|', Borough)

    file.writerow([PostCode, Borough])
    infile.close()

    runs well and all, but I can't find the csv file I created anywhere, normally would find it in my notebook sidebar, but ibm cloud has no side bar, so I'm stock and doesn't know how to call my csv file.

    Please help.

    ------------------------------
    Prosper Popoola
    ------------------------------

    #GlobalAIandDataScience
    #GlobalDataScience


  • 2.  RE: Writing to File using Watson Notebook

    Posted 03/24/20 04:53 AM
    Edited by System Admin 01/20/23 04:20 PM

    Hi Prosper,

    If you are on Watson Studio Cloud, your notebook is running in a hosted non-persistent python environment.

    So, the files you create will be written to the filesystem of that environment. You can list the files with a command such as `!ls -l`in a notebook cell.
    Persistent storage in WS Cloud is managed through Cloud Object Storage (COS), and you have to explicitly copy the files from your local fs to COS.

    Each project is associated to a storage area in COS, called a *bucket*.

    When running in a notebook, you can use either direct COS API to write to that bucket, or use the `project_lib` helper library.
    To do this, you need to:
    1. generate a project token (from your project's Settings tab): 

    2. then insert the access code into your notebook (using the icon at the top):

    3. use `project.save_data()` to copy the file to your project's data assets, e.g.:
    import csv
    csvFileName='Toronto_Neighborhood.csv'
    with open(csvFileName, 'w') as infile:
        file=csv.writer(infile)
        file.writerow(['PostCode', 'Borough'])

    # Copy file into COS project storage using same name:
    project.save_data(csvFileName,csvFileName)

    4. When you switch back to your project's assets tab, you will find the newly created persistent file:


    Screen shot of notebook.:



    ------------------------------
    Philippe Gregoire
    IBM France - TSP & ISV Technical Enablement - Data&AI, IoT Europe
    NICE, France
    ------------------------------
    #GlobalAIandDataScience
    #GlobalDataScience


  • 3.  RE: Writing to File using Watson Notebook

    Posted 03/24/20 05:57 AM
    Edited by System Admin 01/20/23 04:17 PM

    ------------------------------