我为外汇DataFrame阅读了Pandas更改时区,但是我想让我的数据帧时区的时间列与sqlite3数据库的互操作性.
我的pandas数据帧中的数据已经转换为UTC数据,但我不想在数据库中维护此UTC时区信息.
给出从其他来源获得的数据样本,它看起来像这样:
print(type(testdata))
print(testdata)
print(testdata.applymap(type))
Run Code Online (Sandbox Code Playgroud)
得到:
<class 'pandas.core.frame.DataFrame'>
time navd88_ft station_id new
0 2018-03-07 01:31:02+00:00 -0.030332 13 5
1 2018-03-07 01:21:02+00:00 -0.121653 13 5
2 2018-03-07 01:26:02+00:00 -0.072945 13 5
3 2018-03-07 01:16:02+00:00 -0.139917 13 5
4 2018-03-07 01:11:02+00:00 -0.152085 13 5
time navd88_ft station_id \
0 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
1 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
2 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
3 <class 'pandas._libs.tslib.Timestamp'> <class 'float'> <class 'int'>
4 …Run Code Online (Sandbox Code Playgroud) 我不是SOAP和WSDL的专家,但我有Perl代码,我想将其移植到R.
Perl代码看起来像这样(来自https://www.pharmgkb.org/resources/downloads_and_web_services.jsp):
use SOAP::Lite;
import SOAP::Data 'type';
sub main {
my $argcount = scalar (@ARGV);
if ($argcount != 1) {
print "usage: diseases.pl <PharmGKB accession id>\n";
exit -1;
}
# make a web services call to server
my $call = SOAP::Lite
-> readable (1)
-> uri('PharmGKBItem')
-> proxy('http://www.pharmgkb.org/services/PharmGKBItem')
-> searchDisease($ARGV[0]);
if ($call->fault) {
print $call->faultcode . ": " . $call->faultstring . "\n";
} else {
my $result = $call->result;
Run Code Online (Sandbox Code Playgroud)
阅读有关rsoap和SSOAP包的内容,但没有得到任何好消息.我需要的是完全支持,例如调用服务并提供库来解析输出.我更喜欢一些库而不是原始编码.我对XML包很好,对RCurl不太好.我认为R中没有好的和当前的(积极维护的)支持是正确的吗?
t.ct = as.POSIXct("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z")
t.lt = as.POSIXlt("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z")
t.st = strptime("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z")
Run Code Online (Sandbox Code Playgroud)
这些似乎是同一时期:
> t.ct -t.lt
Time difference of 0 secs
> t.ct -t.st
Time difference of 0 secs
> str(t.ct)
POSIXct[1:1], format: "2009-01-04 21:19:00"
> str(t.lt)
POSIXlt[1:1], format: "2009-01-04 21:19:00"
> str(t.st)
POSIXlt[1:1], format: "2009-01-04 21:19:00"
>
Run Code Online (Sandbox Code Playgroud)
但这些似乎有不同的时区信息,这不是我所期望的:
> strftime(t.ct,"%Y-%m-%d %H:%M:%S %z")
[1] "2009-01-04 21:19:00 -0500"
> strftime(t.lt,"%Y-%m-%d %H:%M:%S %z")
[1] "2009-01-04 21:19:00 +1200"
> strftime(t.st,"%Y-%m-%d %H:%M:%S …Run Code Online (Sandbox Code Playgroud) 我正在尝试这个:
import pandas as pd
import sqlite3
import datetime, pytz
#nowtime=datetime.datetime.now(pytz.utc)
nowtime=datetime.datetime.now()
print(nowtime)
df = pd.DataFrame(columns=list('ABCD'))
df.loc[0]=(3,0.141,"five-nine",nowtime)
df.loc[1]=(1,0.41,"four-two",nowtime)
print(df)
db = sqlite3.connect(':memory:')
c = db.cursor()
c.execute('create table if not exists ABCD ( A integer, B real, C text, D timestamp );')
c.execute('insert into ABCD (A,B,C, D) values (?,?,?,?);',(1,2.2,'4',nowtime))
c.executemany('insert into ABCD (A,B,C, D) values (?,?,?,?);',df.to_records(index=False))
db.commit()
print(pd.read_sql('select * from ABCD;',db))
Run Code Online (Sandbox Code Playgroud)
并得到这个:
2018-03-07 19:09:58.584953
A B C D
0 3 0.141 five-nine 2018-03-07 19:09:58.584953
1 1 0.410 four-two 2018-03-07 19:09:58.584953
A …Run Code Online (Sandbox Code Playgroud) 'at' 是一个 UNIX/BSD/Linux 编程工具,我在调度一些操作预测模型时使用它。在我的 Mac 笔记本电脑上测试我的一些脚本时,我发现该at工具毫无错误地接受了作业提交,并将它们报告在队列中,但最终没有执行它们。
at由于该工具的名称很普通,因此很难为该工具搜索有用的答案。但是,我看到OSX El Capitan 上的 crontab 是否损坏?在努力解决这个问题的同时。
$ at now + one minute
echo "hello world" |say
^D
$ atq # list at jobs...
7 Mon Mar 13 14:31:00 2017
$
Run Code Online (Sandbox Code Playgroud) 在考虑使用 dplyr 将数据添加到表中时,我看到了/sf/answers/1874936101/,但文档说db_insert_table()已弃用。
?db_insert_into()
...
db_create_table() and db_insert_into() have been deprecated in favour of db_write_table().
...
Run Code Online (Sandbox Code Playgroud)
我尝试改用未弃用的选项db_write_table(),但无论有没有append=选项,它都会失败:
require(dplyr)
my_db <- src_sqlite( "my_db.sqlite3", create = TRUE) # create src
copy_to( my_db, iris, "my_table", temporary = FALSE) # create table
newdf = iris # create new data
db_write_table( con = my_db$con, table = "my_table", values = newdf) # insert into
# Error: Table `my_table` exists in database, and both overwrite and append are FALSE …Run Code Online (Sandbox Code Playgroud) 如果你有一个 R highcharter 对象,你如何将它导出到一个可以包含在 iframe 中的独立 html 文件:
例如:
library(highcharter)
hc <- hchart(cbind(fdeaths, mdeaths), separate = FALSE)
Run Code Online (Sandbox Code Playgroud)
然后,我正在寻找类似的东西:
save_as_html(hc,filename)
Run Code Online (Sandbox Code Playgroud)
Matlab 的 HighChart 代码是这样工作的:
hc = HighChart('datetime');
hc.series{1}.data = [ttt(ii3day), -vd(ii3day)];
hc.save('plot_hc.html');
Run Code Online (Sandbox Code Playgroud)
生成的plot_hc.html代码类似于:
<!DOCTYPE html>
<html>
<body>
<div id="con_8rHh7YjNg4" class="HighChart" style="width:800px; height:400px;"></div></body>
<footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<script>
$(function () {
$('#con_8rHh7YjNg4').highcharts({
chart:{type:'line',zoomType:'x',panning:'true',panKey:'shift'},
title:{text:'observations'},
xAxis:{title:{text:'UTC Time'},type:'datetime'},
yAxis:{title:{text:'feet'}},
series:[{name:'Observations',data:[[1508371860000,-1.089000e+01],[1508371920000,-1.086000e+01],[1508371980000,-1.085000e+01],[1508372040000,-1.085000e+01],[1508372100000,-1.084000e+01],[1508372160000,-1.083000e+01],[1508372220000,-1.081000e+01],[1508372280000,-1.082000e+01],[1508372340000,-1.081000e+01],[1508372400000,-1.080000e+01],[1508372460000,-1.080000e+01],[1508372520000,-1.078000e+01],[1508372580000,-1.078000e+01],[1508372640000,-1.077000e+01],[1508372700000,-1.077000e+01],[1508372760000,-1.075000e+01],[1508372820000,-1.075000e+01],[1508372880000,-1.076000e+01],[1508372940000,-1.073000e+01],[1508373000000,-1.070000e+01],[1508373060000,-1.071000e+01],[1508373120000,-1.072000e+01],[1508373180000,-1.071000e+01],[1508373240000,-1.069000e+01],[1508373300000,-1.068000e+01],[1508373360000,-1.068000e+01],[1508373420000,-1.067000e+01],[1508373480000,-1.066000e+01],[1508373540000,-1.067000e+01],[1508373600000,-1.064000e+01],[1508373660000,-1.063000e+01],[1508373720000,-1.062000e+01],[1508373780000,-1.062000e+01],
});
});
</script>
</footer>
</html>
Run Code Online (Sandbox Code Playgroud)
这种 html 文件很容易作为 iframe 与我机构的内容管理系统一起工作,我想用 R 做一些类似的事情。
我试过,export_hc(hc,"plot_hc.html")但它似乎只是 …
我有个问题。我有一个运行良好的 bash 脚本。
while read val1 val2 val3
do
echo "ncap2 -Oh -s'TOPOBATHY(($val1,$val2))=$val3.'"
done < $tmpdir/tmp1 > $tmpdir/tmp2
Run Code Online (Sandbox Code Playgroud)
我只想对 val1 和 val2 执行一次操作,减去 1。我尝试直接减去,但它不起作用。有没有办法做到这一点。在此先感谢您的帮助!
while read val1 val2 val3
do
echo "ncap2 -Oh -s'TOPOBATHY(($val1-1),($val2-1))=$val3.'"
done < $tmpdir/tmp1 > $tmpdir/tmp2
Run Code Online (Sandbox Code Playgroud)