我在csv文件中配对了值.配对值都不一定是唯一的.我想将这个大型清单拆分成独立的完整集,以便进一步分析.
为了说明,我的"megalist"就像:
megalist = [['a', 'b'], ['a', 'd'], ['b', 'd'],['b', 'f'], ['r', 's'], ['t', 'r']...]
Run Code Online (Sandbox Code Playgroud)
最重要的是,输出将保留配对值列表(即,不合并值).理想情况下,输出最终会导致不同的csv文件,以便以后进行单独分析.例如,这个预言家将是:
completeset1 = [['a', 'b'], ['a', 'd'], ['b', 'd'], ['b', 'f']]
completeset2 = [['r', 's'], ['t', 'r']]
...
Run Code Online (Sandbox Code Playgroud)
在图论背景中,我试图获取互斥子图的巨大图(其中配对值是连接顶点)并将它们拆分成更易于管理的独立图.感谢您的任何意见!
编辑1:这使我处于一个可以向前迈进的地方.再次感谢!
import sys, csv
import networkx as nx
megalist = csv.reader(open('megalistfile.csv'), delimiter = '\t')
G = nx.Graph()
G.add_edges_from(megalist)
subgraphs = nx.connected_components(G)
output_file = open('subgraphs.txt','w')
for subgraph in subgraphs:
output_line = str(G.edges(subgraph)) + '\n'
output_file.write(output_line)
output_file.close()
Run Code Online (Sandbox Code Playgroud) 像其他人一样,我试图让 Google 刷新令牌工作,以便运行复制和重命名文件的计划任务。
当我第一次在终端内手动验证时,我的 url 以 &access_type=offline 结尾。但是,当我进入并尝试在 ipython 中手动使用 gauth.Refresh() 时,它失败并出现与我的凭据文件过期时相同的错误:
pydrive.auth.RefreshError: No refresh_token found.Please set access_type of OAuth to offline.
Run Code Online (Sandbox Code Playgroud)
我如何实际将 access_type 设置为离线?任何建议都非常感谢。
我的脚本:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("GoogleDriveCredentials.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
print "Google Drive Token Expired, Refreshing"
gauth.Refresh()
else:
# Initialize …Run Code Online (Sandbox Code Playgroud)