当前位置: 首页>>代码示例>>Python>>正文


Python Network.pandas_load_tsv_to_net方法代码示例

本文整理汇总了Python中clustergrammer.Network.pandas_load_tsv_to_net方法的典型用法代码示例。如果您正苦于以下问题:Python Network.pandas_load_tsv_to_net方法的具体用法?Python Network.pandas_load_tsv_to_net怎么用?Python Network.pandas_load_tsv_to_net使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clustergrammer.Network的用法示例。


在下文中一共展示了Network.pandas_load_tsv_to_net方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from clustergrammer import Network [as 别名]
# 或者: from clustergrammer.Network import pandas_load_tsv_to_net [as 别名]
def main():

  import time
  start_time = time.time()
  import pandas as pd
  import StringIO

  # import network class from Network.py
  from clustergrammer import Network

  net = Network()

  # load data to dataframe 
  # net.load_tsv_to_net('txt/example_tsv_network.txt')
  # net.load_tsv_to_net('txt/mat_1mb.txt')

  # choose file 
  ################
  # file_buffer = open('txt/col_categories.txt')
  file_buffer = open('txt/example_tsv_network.txt'  )


  buff = StringIO.StringIO( file_buffer.read() )
  net.pandas_load_tsv_to_net(buff)

  # filter rows 
  views = ['filter_row_sum','N_row_sum']

  # distance metric 
  dist_type = 'cosine'

  # linkage type 
  linkage_type = 'average'


  net.make_clust(dist_type=dist_type, views=views, calc_col_cats=True,\
  linkage_type=linkage_type)

  net.write_json_to_file('viz', 'json/mult_view.json', 'no-indent')

  elapsed_time = time.time() - start_time
  print('\n\n\nelapsed time: '+str(elapsed_time))
开发者ID:jjdblast,项目名称:clustergrammer.js,代码行数:44,代码来源:mock_web_app_load.py

示例2: main

# 需要导入模块: from clustergrammer import Network [as 别名]
# 或者: from clustergrammer.Network import pandas_load_tsv_to_net [as 别名]
def main( buff, inst_filename, mongo_address, viz_id):
  import numpy as np
  import flask
  from bson.objectid import ObjectId
  from pymongo import MongoClient
  from flask import request
  from clustergrammer import Network
  import StringIO

  ##############################
  # set up database connection 
  ##############################
  # set up connection 
  client = MongoClient(mongo_address)
  db = client.clustergrammer

  # get placeholder viz data 
  viz_id = ObjectId(viz_id)
  found_viz = db.networks.find_one({'_id':viz_id})

  try:
    ########################
    # load and cluster 
    ########################

    # initiate class network 
    net = Network()
    # net.load_lines_from_tsv_to_net(file_lines)  
    net.pandas_load_tsv_to_net(buff)

    # swap nans for zero 
    net.swap_nan_for_zero()

    # deprecated clustering module
    ####################################

    # # fast mult views takes care of pre-filtering
    # net.fast_mult_views()

    ####################################

    net.make_filtered_views(dist_type='cosine', dendro=True, \
      views=['filter_row_sum'], linkage_type='average')

    ###############################
    # save to database 
    ###############################

    export_dat = {}
    export_dat['name'] = inst_filename
    export_dat['dat'] = net.export_net_json('dat')
    export_dat['source'] = 'user_upload'
    # save dat to separate document 
    dat_id = db.network_data.insert(export_dat)

    update_viz = net.viz 
    update_dat = dat_id

  except:
    print('\n-----------------------')
    print('error in clustering')
    print('-----------------------\n')
    update_viz = 'error'
    update_dat = 'error'

  # update found_viz 
  found_viz['viz'] = update_viz
  found_viz['dat'] = update_dat

  # update found_viz in database 
  db.networks.update_one( {'_id':viz_id}, {'$set': found_viz} )

  ############################
  # end database connection 
  ############################
  client.close()


  
开发者ID:aeron15,项目名称:clustergrammer,代码行数:78,代码来源:load_tsv_file.py


注:本文中的clustergrammer.Network.pandas_load_tsv_to_net方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。