我不知道(也不可能找到例子)的连接字符串传递给sqlalchemy的create_engine(),让我连接到mysql数据库Amazon Web Service RDS。文档很简单,但我绊倒了。文档状态:
mysql+mysqldb://<user>:<password>@<host>[:<port>]/<dbname>
Run Code Online (Sandbox Code Playgroud)
让我们说:
hellothereComp<'/"/>{}]:["licatedsandbox.cbaspyqqzfab.us-west-2.rds.amazonaws.com3306nameofdatabase这有什么问题?
conn_str = 'mysql+mysqldb://<hellothere>:<Comp<'/"/>{}]:["licated>@<sandbox.cbaspyqqzfab.us-west-2.rds.amazonaws.com>[:<3306>]/<nameofdatabase>'
engine = sqlalchemy.create_engine(conn_str, echo=True)
Run Code Online (Sandbox Code Playgroud)
错误信息
Traceback (most recent call last): File
"C:/GitHub/blah/data/__init__.py", line 16, in <module> main() File
"C:/GitHub/blah/data/__init__.py", line 12, in main init_db() File
"C:/GitHub/blah/data/__init__.py", line 8, in init_db
DbSessionFactory.global_init(db_file=dbfilepath) File
"C:\GitHub\blah\data\dbsession.py", line 25, in global_init engine =
sqlalchemy.create_engine(conn_str, echo=True) File
"C:\Python\Anaconda3\envs\CE\lib\site-packages\sqlalchemy\engine\__init__.py",
line 387, in create_engine return strategy.create(*args, **kwargs)
File
"C:\Python\Anaconda3\envs\CE\lib\site-packages\sqlalchemy\engine\strategies.py", …Run Code Online (Sandbox Code Playgroud) 我很难构建一个有效的程序,该程序可以添加和乘以概率密度函数来预测完成两个流程步骤所需的时间分布。
让“a”代表完成过程“A”所需时间的概率分布函数。零天 = 10%,一天 = 40%,两天 = 50%。让“b”代表完成过程“B”需要多长时间的概率分布函数。零天 = 10%,一天 = 20%,以此类推。
进程“B”在进程“A”完成之前无法启动,因此“B”依赖于“A”。
a <- c(.1, .4, .5)
b <- c(.1,.2,.3,.3,.1)
Run Code Online (Sandbox Code Playgroud)
如何计算完成“A”和“B”的时间的概率密度函数?
这是我所期望的或以下示例的输出:
totallength <- 0 # initialize
totallength[1:(length(a) + length(b))] <- 0 # initialize
totallength[1] <- a[1]*b[1]
totallength[2] <- a[1]*b[2] + a[2]*b[1]
totallength[3] <- a[1]*b[3] + a[2]*b[2] + a[3]*b[1]
totallength[4] <- a[1]*b[4] + a[2]*b[3] + a[3]*b[2]
totallength[5] <- a[1]*b[5] + a[2]*b[4] + a[3]*b[3]
totallength[6] <- a[2]*b[5] + a[3]*b[4]
totallength[7] <- a[3]*b[5]
print(totallength)
[1] [1] 0.01 0.06 0.16 0.25 0.28 …Run Code Online (Sandbox Code Playgroud) 我在R中编写了一个函数来计算按月数计算的累计总数,但是随着数据集变大,我的方法的执行时间呈指数级增长.我是新手R程序员,你能帮我提高效率吗?
函数和我调用函数的方式:
accumulate <- function(recordnum,df){
sumthese <- (df$subject == df$subject[recordnum]) &
(df$month <= df$month[recordnum])
sum(df$measurement[sumthese])
}
set.seed(42)
datalength = 10
df <- data.frame(measurement = runif(1:datalength),
subject=rep(c("dog","cat"),each =datalength/2),
month=rep(seq(datalength/2,1,by=-1)))
system.time(df$cumulative <- sapply(1:datalength,accumulate,df))
Run Code Online (Sandbox Code Playgroud)
输入数据帧:
> df
measurement subject month
1 0.4577418 dog 5
2 0.7191123 dog 4
3 0.9346722 dog 3
4 0.2554288 dog 2
5 0.4622928 dog 1
6 0.9400145 cat 5
7 0.9782264 cat 4
8 0.1174874 cat 3
9 0.4749971 cat 2
10 0.5603327 cat 1
Run Code Online (Sandbox Code Playgroud)
输出数据帧: …
我想在 docker 容器中运行金字塔应用程序,但我在 Dockerfile 中为正确的语法而苦苦挣扎。Pyramid 没有官方的 Dockerfile,但我发现这个网站推荐使用 Ubuntu 基础镜像。 https://runnable.com/docker/python/dockerize-your-pyramid-application
但这适用于 Python 2.7。任何想法如何将其更改为 3.5?这是我尝试过的:
文件
FROM ubuntu:16.04
RUN apt-get update -y && \
apt-get install -y python3-pip python3-dev && \
pip3 install --upgrade pip setuptools
# We copy this file first to leverage docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip3 install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD [ "pserve development.ini" ]
我从命令行运行它:
docker build -t testapp .
但这会产生一系列以这个结尾的错误
FileNotFoundError: [Errno 2] 没有那个文件或目录:'/usr/local/lib/python3.5/dist-packages/appdirs-1.4.3.dist-info/METADATA' 命令'/bin/sh -c …
python-3.x ×2
r ×2
amazon-rds ×1
dataframe ×1
dockerfile ×1
mysql ×1
performance ×1
pyramid ×1
python ×1
sapply ×1
sqlalchemy ×1
statistics ×1
ubuntu ×1