我正在尝试运行以下代码以从 YAML 文件创建虚拟 Python 环境。我在 Ubuntu 服务器的命令行中运行代码。虚拟环境命名为 py36。当我运行下面的代码时,我收到以下消息。环境也没有被创建。这个问题是否是因为我必须使用 pip 而不是 Anaconda 安装几个软件包?有谁知道如何解决这个问题?
我按照以下示例创建了 YAML 文件:
https://datascience.stackexchange.com/questions/24093/how-to-clone-python-working-environment-on-another-machine
Run Code Online (Sandbox Code Playgroud)
conda env create -f py36.yml
Run Code Online (Sandbox Code Playgroud)
name: py36
channels:
- anaconda
- cvxgrp
- conda-forge
- defaults
dependencies:
- beautifulsoup4=4.6.3=py36_0
- patsy=0.5.1=py36_0
- sqlite=3.25.3=ha441bb4_0
- tk=8.6.8=ha441bb4_0
- asn1crypto=0.24.0=py36_1003
- ca-certificates=2018.11.29=ha4d7672_0
- certifi=2018.11.29=py36_1000
- cffi=1.11.5=py36h5e8e0c9_1
- clangdev=4.0.0=default_0
- cryptography=2.3.1=py36hdbc3d79_1000
- cryptography-vectors=2.3.1=py36_1000
- cycler=0.10.0=py_1
- fftw=3.3.8=h470a237_0
- freetype=2.9.1=h6debe1e_4
- glpk=4.65=h16a7912_1
- gmp=6.1.2=hfc679d8_0
- icu=58.2=h0a44026_1000
- idna=2.8=py36_1000
- kiwisolver=1.0.1=py36h2d50403_2
- lapack=3.6.1=1
- libiconv=1.15=h1de35cc_1004
- libpng=1.6.35=ha92aebf_2
- …Run Code Online (Sandbox Code Playgroud) 当我运行我的程序时,出现以下错误,该程序具有下面定义的函数。我认为这是
valid_actions = filter(lambda x: x != random.choice(maxQactions)
Run Code Online (Sandbox Code Playgroud)
导致错误的部分。有谁知道问题是什么,或者建议如何解决它?谢谢。
错误:
choose_action
action = random.choice(valid_actions)
File "/Users/UserName/anaconda/lib/python2.7/random.py", line 275, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)
代码:
def choose_action(self, state):
self.state = state
self.next_waypoint = self.planner.next_waypoint()
action_selections = self.Q[state]
maxQ = max(action_selections.items(), key=lambda x: x[1])[1]
maxQactions = []
for action, Q in self.Q[state].items():
if Q == maxQ:
maxQactions.append(action)
if self.learning:
choose_using_epsilon = random.random() < 1 - self.epsilon
if not …Run Code Online (Sandbox Code Playgroud) 我有下面的函数,它在数组中搜索重复的条目,然后返回重复项的列表。我想加快这段代码的速度,有人能建议一种更有效的方法吗?
代码:
def findDupe(array):
dupelist = []
for i in range(len(array)):
for j in range(len(array)):
comp1 = array[i]
comp2 = array[j]
if comp1 == comp2 and i!=j:
if comp2 not in dupelist:
dupelist.append(comp2)
return dupelist
Run Code Online (Sandbox Code Playgroud) 我有一个 jupyter 笔记本,可以创建图像的本地缓存。我想在运行特定单元之前清除缓存。有谁知道这是怎么做到的吗?我试过:
import gc
gc.collect()
Run Code Online (Sandbox Code Playgroud)
但它没有效果。我还尝试清除 chrome 中的所有 cookie 和缓存,但这也确实有效。
我有数据框,如下面的示例数据.我正在尝试将数据帧中的一行转换为dict,如下面所需的输出.但是当我使用to_dict时,我得到了indice和列值.有谁知道如何将行转换为dict,如所需的输出?任何提示非常感谢.
Sample data:
print(catStr_df[['Bottle Volume (ml)', 'Pack']][:5])
Bottle Volume (ml) Pack
595 750 12
1889 750 12
3616 1000 12
4422 750 12
5022 750 12
Code:
v = catStr_df[catStr_df['Item Number']==34881][['Bottle Volume (ml)', 'Pack']]\
.drop_duplicates(keep='first').to_dict()
v
Output:
{'Bottle Volume (ml)': {9534: 1000}, 'Pack': {9534: 12}}
Desired output:
{'Bottle Volume (ml)': 1000, 'Pack': 12}
Run Code Online (Sandbox Code Playgroud) 我是新手hive,可以使用一些提示.
我试图从导出查询结果hive作为csv.当我尝试将它们从CLI中移出时:
hive -e 'select * from table'>OutPut.txt
Run Code Online (Sandbox Code Playgroud)
我得到一个包含所有记录但没有列标题的文本文件.有没有人有关于如何将带有列标题的查询结果导出到csv文件的提示?
如果我在色调中运行查询,然后下载结果,csv我得到一个csv列标题,但没有记录.如果有人有关于如何从记录和列标题的hue下载查询结果的提示,我将非常感激.
我正在使用 jupyter 笔记本,并且正在处理 markdown 文件。我使用的 Mac 版本为 Sierra 10.12.16。我想将 markdown 转换为 pdf,我想知道最简单的方法是什么。我读过很多关于安装 pandoc 或在atom中使用包的文章。我想知道 Jupyter Notebook 是否有一种简单的方法可以将 Markdown 文件转换为 pdf。看起来确实应该有,但我很难找到它。
我有一个 jupyter 笔记本,它是 markdown 和代码的混合体。最后我想将其呈现为 pdf 报告并隐藏代码。我仍然想看到代码的输出、图表和表格,我只是不想在最终报告中看到代码。我发现下面的帖子包含以下代码,如果将其添加到笔记本中,则会创建一个切换按钮,可用于隐藏或显示输入代码。问题是我的报告顶部有一个切换按钮。有谁知道如何做到这一点?
邮政:
代码:
<script>
function code_toggle() {
if (code_shown){
$('div.input').hide('500');
$('#toggleButton').val('Show Code')
} else {
$('div.input').show('500');
$('#toggleButton').val('Hide Code')
}
code_shown = !code_shown
}
$( document ).ready(function(){
code_shown=false;
$('div.input').hide()
});
</script>
<form action="javascript:code_toggle()"><input type="submit" id="toggleButton" value="Show Code"></form>
Run Code Online (Sandbox Code Playgroud) I\xe2\x80\x99m 尝试从我的 aws 数据目录中的数据库获取表的列表。I\xe2\x80\x99m 尝试使用 boto3。我\xe2\x80\x99m 在 aws 上的 sagemaker 笔记本中运行下面的代码。它会永远运行(比如超过 30 分钟)并且不会返回任何结果。test_db 中只有 4 个表。我的目标是运行类似的代码作为 awsglueetl 作业的一部分,我将在编辑后的 awsetl 作业脚本中运行该代码。有谁知道问题可能是什么或建议如何做到这一点?
\n\n代码:
\n\nimport boto3\nfrom pprint import pprint\n\nglue = boto3.client('glue', region_name='us-east-2')\n\nresponse = glue.get_tables(\n DatabaseName=\xe2\x80\x98test_db\xe2\x80\x99\n)\n\nprint(pprint(response['TableList']))\nRun Code Online (Sandbox Code Playgroud)\n 我使用下面的 llama-index 代码从保存的文本语料库创建索引对象。然后,我加载保存的索引对象并查询它以生成响应。我正在使用 openai apikey,因此我可以使用 chatgpt 模型来获得 LLM。我想知道是否可以使用相同的代码或修改版本来使用开源 LLM,例如我已在本地计算机上下载模型权重的 llama-7b-chat。有谁知道这是否可行,您能建议我如何更新下面的代码才能使用本地托管的开源LLM吗?
代码:
# creating index from corpus
from config import api_key, old_api_key, personal_api_key
import os
os.environ['OPENAI_API_KEY'] = old_api_key
# Load you data into 'Documents' a custom type by LlamaIndex
# from typing_extensions import Protocol
from llama_index import SimpleDirectoryReader
documents = SimpleDirectoryReader('./data').load_data()
from llama_index import GPTVectorStoreIndex
index = GPTVectorStoreIndex.from_documents(documents)
# save storage context
storage_context_dict=index.storage_context.to_dict()
import json
# Serialize data into file:
json.dump( storage_context_dict, open( "general_attributes_storage_context_dict.json", 'w' ) )
# load saved context …Run Code Online (Sandbox Code Playgroud) python ×6
python-3.x ×2
algorithm ×1
aws-glue ×1
boto3 ×1
conda ×1
dictionary ×1
hive ×1
hiveql ×1
hue ×1
list ×1
llama ×1
llama-index ×1
macos ×1
pandas ×1
performance ×1
python-2.7 ×1
q-learning ×1