我正在使用大型数据框,并且已经遇到RAM限制.此时,我可能需要在磁盘上使用序列化版本.有一些软件包支持内存不足的操作,但我不确定哪一个适合我的需求.我宁愿将所有内容保存在数据框中,因此ff包看起来很令人鼓舞,但仍然存在兼容性问题,我无法解决.
当您意识到数据已经达到内存不足时,第一个可以实现的工具是什么?
我正在使用一个使用长SQL字符串的R脚本,我希望保持查询相对没有其他标记,以便允许在编辑器和应用程序之间进行复制和粘贴.我还希望能够跨行分割查询以提高可读性.
在RODBC文档中,该paste函数用于从单独的块中构建查询,但我更喜欢不那么笨拙且引号和逗号较少的东西.谢谢你的帮助.
我目前正在使用cast熔化的表来计算ID变量ID1(行名称)和ID2(列标题)组合中每个值的总和,以及每行使用的总计margins="grand_col".
c <- cast(m, ID1 ~ ID2, sum, margins="grand_col")
ID1 ID2a ID2b ID2c ID2d ID2e (all)
1 ID1a 6459695 885473 648019 453613 1777308 10224108
2 ID1b 7263529 1411355 587785 612730 2458672 12334071
3 ID1c 7740364 1253524 682977 886897 3559283 14123045
Run Code Online (Sandbox Code Playgroud)
到目前为止,所以R-like.
然后我将每个单元格除以其行总数以获得总数的百分比.
c[,2:6]<-c[,2:6] / c[,7]
Run Code Online (Sandbox Code Playgroud)
这看起来像kludgy.我应该做些什么cast或者可能在plyr第一个命令中处理保证金计算的百分比?
谢谢,马特
因为LiveServerTestCase继承自TransactionTestCase,默认行为是在每个测试方法结束时删除测试数据。我想使用LiveServerTestCase该类,但保留方法与方法之间的测试数据。在本例中,test2失败是因为数据库在test1.
我的理解是,如果我使用TestCase,它会在每次测试结束时回滚事务并将数据库返回到其起始条件。我可以在使用 时模仿这种行为LiveServerTestCase吗?
class TestTheTests(LiveServerTestCase):
@classmethod
def setUpTestData(cls):
print('running setUpTestData')
call_command('loaddata', 'datasources.yaml' )
@classmethod
def setUpClass(cls):
print('starting setUpClass')
cls.setUpTestData() # load the data for the entire test class
super().setUpClass()
@classmethod
def tearDownClass(cls):
print('finished tearDownClass')
super().tearDownClass()
def setUp(self):
self.browser = webdriver.Chrome()
def tearDown(self):
self.browser.quit()
Run Code Online (Sandbox Code Playgroud)
当我同时运行这两个测试时,此测试通过:
def test1(self):
print('test 1 running')
self.assertEquals(8, DataSource.objects.count(),'There should be 8 DataSource objects in test1')
Run Code Online (Sandbox Code Playgroud)
此测试失败:
def test2(self):
print('test 2 running')
self.assertEquals(8, DataSource.objects.count(),'There …Run Code Online (Sandbox Code Playgroud) 在我的routes.js文件的以下代码中,我可以成功填充一个名为的Mongoose对象中的一些引用Map.当我查看页面时,控制台会打印完全填充popmap的editor对象版本.
app.get('/map/:id', function(req, res){
Map
.findOne({ _id: req.map._id })
.populate('_editors')
.run(function (err, popmap) {
console.log('The editors are %s', popmap._editors);
});
res.render('maps/show', {
title: req.map.title,
map: req.map
});
});
Run Code Online (Sandbox Code Playgroud)
但是,我还没想到如何执行填充步骤,使得结果对象仍然在渲染代码的范围内.换句话说,如何将填充的对象传递给Jade模板而不是仅仅发送req.map?