我正在使用renjin,我正在尝试使用我在java代码中使用r代码生成的值,例如:
int x = 7;
try
{
engine.eval("tmp<-c(x, 4)");
engine.eval("print(tmp)");
}
catch (ScriptException ex)
{
;
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为引擎显然无法使用x.有没有简单的方法来解决这个问题?
我使用以下代码(基于示例 pandas-gbq-migration)如下:
from google.cloud import bigquery
import pandas
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "link_to_credentials.json"
df = pandas.DataFrame(
{
'my_string': ['a', 'b', 'c'],
'my_int64': [1, 2, 3],
'my_float64': [4.0, 5.0, 6.0],
}
)
client = bigquery.Client()
dataset_ref = client.dataset('TMP')
table_ref = dataset_ref.table('yosh_try_uload_from_client')
client.load_table_from_dataframe(df, table_ref).result()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
pyarrow or fastparquet is required for parquet support
Run Code Online (Sandbox Code Playgroud)
在看了一些像这样的问题之后:
我知道我需要更改配置中的某些内容(也许添加架构?)
有人可以在这里帮助我吗,我无法从文档中了解如何做到这一点。
提前致谢!
我正在寻找能够获得年+周数+周日的功能,并返回日期,例如:
我想输入以下3个
2015
Monday
23
Run Code Online (Sandbox Code Playgroud)
并获得所需的输出:
"2015-06-08"
Run Code Online (Sandbox Code Playgroud)
在网上搜索之后,似乎在其他语言中存在相同的问题但在R中没有:
任何帮助都会很棒!
为了使用Pyhton 3.3和django 1.8,我使用Virtualenv(用于Web应用程序 pythonanywhere)
我按照以下说明操作:https: //www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango
进入控制台,显示我使用的是3.3版本
(django18)12:04 ~ $ python
Python 3.3.6 (default, Jan 28 2015, 17:27:09)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Run Code Online (Sandbox Code Playgroud)
这也是我想要在我的网络应用中使用的版本:
Python version:3.3 (in the code pane)
Run Code Online (Sandbox Code Playgroud)
但是,当我将Virtualenv窗格指向Virtualenv目录(名为django18)时,我收到以下警告:
This virtualenv seems to have the wrong Python version (2.7 instead of 3.3).
Run Code Online (Sandbox Code Playgroud)
这是所有控制台(我在创建应用程序并指定Python版本后运行它):
06:43 ~ $ mkvirtualenv --python=/usr/bin/python3.3 django18
Running virtualenv with interpreter /usr/bin/python3.3
Using base prefix '/usr'
New python executable in django18/bin/python3.3
Not overwriting existing …Run Code Online (Sandbox Code Playgroud) 我想创建一个异步读取多个 Pandas 数据帧的代码,例如从 CSV 文件(或从数据库)
我编写了以下代码,假设它应该更快地导入两个数据帧,但它似乎执行得更慢:
import timeit
import pandas as pd
import asyncio
train_to_save = pd.DataFrame(data={'feature1': [1, 2, 3],'period': [1, 1, 1]})
test_to_save = pd.DataFrame(data={'feature1': [1, 4, 12],'period': [2, 2, 2]})
train_to_save.to_csv('train.csv')
test_to_save.to_csv('test.csv')
async def run_async_train():
return pd.read_csv('train.csv')
async def run_async_test():
return pd.read_csv('test.csv')
async def run_train_test_asinc():
df = await asyncio.gather(run_async_train(), run_async_test())
return df
start_async = timeit.default_timer()
async_train,async_test=asyncio.run(run_train_test_asinc())
finish_async = timeit.default_timer()
time_to_run_async=finish_async-start_async
start = timeit.default_timer()
train=pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
finish = timeit.default_timer()
time_to_run_without_async = finish - start
print(time_to_run_async<time_to_run_without_async)
Run Code Online (Sandbox Code Playgroud)
为什么它在非异步版本中读取两个数据帧的速度更快?
只是为了清楚起见,我真的要从中读取数据, …
我目前正在使用forecast.gts (hts package)单个外部变量,该变量为所有单独的时间序列保存相同的值,以便创建 30 天的预测,但是我想包括另一个外部回归器,它为每个单独的 ts 保存不同的值。
我将问题简化如下:
我有 4 个 ts 需要预测(它们是品牌和非大集团每日花费的保险付费搜索),分为两组:

我有兴趣应用两个外部回归:
因此,对于第一个外部回归器,我设法使用forecast.hts以下内容:
library(ggplot2)
library(plyr)
library(hts)
library(ts)
library(data.table)
library(reshape2)
horizon<-30
data1<-dcast(data, Date ~ Brand+Venue, sum , value.var="Spend")
data[is.na(data)] <- 0
abcd<-ts(as.matrix(data1[,2:5]),frequency=7)
#abcd<-abcd+0.000001
Brand <- c("Brand","Brand","NonBrand","NonBrand")
Venue <- rep(c("Google","MSN"), 2)
gcd <- rbind(Brand,Venue)
rownames(gcd) <- c("Brand","Venue")
x <- gts(abcd, groups = gcd)
dates = data.frame(Date=seq.Date(min(data$Date,na.rm =T), max(data$Date,na.rm =T), by …Run Code Online (Sandbox Code Playgroud) 我目前正在使用一个数据框,它的每个单元格中都有一个类型为列表(带有字符串)的列。我有兴趣申请value.counts()它,好像所有列表都将被连接到一个巨大的列表中(试图这样做,但效果不佳)
我拥有的数据结构的玩具示例:
import pandas as pd
df_list = pd.DataFrame({'listcol':[['a','b','c'],['a','b','c']]})
print df_list
listcol
0 [a, b, c]
1 [a, b, c]
Run Code Online (Sandbox Code Playgroud)
value.counts()如果它是一个大的连接列表,我想像它一样申请它:
#desired output:
df=pd.DataFrame(['a','b','c','a','b','c'])
df.columns = ['col']
df.col.value_counts() #desired output!
b 2
c 2
a 2
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我之前要求过解决方案,但显然无法帮助,因为 renjin 仍然处于实验阶段……但也许有人可以将我收到的错误消息翻译成简单的英语?
也许我可以确定我是否可以合理地希望在合理的时间内解决这个问题,或者我是否应该放弃仁进。
这是消息:
Exception in thread "AWT-EventQueue-0" org.renjin.eval.EvalException: object 'C_hclust' not found
Run Code Online (Sandbox Code Playgroud)
这是代码:
private void cluster() {
try {
this.engine.eval("dis<-dist(myMatrix, \"binary\")");
} catch (ScriptException ex) {System.out.println(1);
Logger.getLogger(RWorker.class.getName()).log(Level.SEVERE, null, ex);
}
try {
this.engine.eval("clus<-hclust(dis)");
} catch (ScriptException ex) {System.out.println(3);
Logger.getLogger(RWorker.class.getName()).log(Level.SEVERE, null, ex);
}
try {
this.engine.eval("plot(clus)");
} catch (ScriptException ex) {System.out.println(4);
Logger.getLogger(RWorker.class.getName()).log(Level.SEVERE, null, ex);
}
}
Run Code Online (Sandbox Code Playgroud)
然而,我没有得到任何印刷品。
python ×4
r ×4
pandas ×3
java ×2
renjin ×2
async-await ×1
date ×1
django ×1
forecasting ×1
jri ×1
time-series ×1