Pandas选择不连续的数据帧日期切片?(Pandas select discontinuous dataframe date slices?)
我有一个带有日期时间索引的pandas DF:这个选择正常
threeyrs=actdf['01/01/2010':'12/31/2012']
但我想得到这样的东西(排除2010年):
threeyrs=actdf['01/01/2009':'12/01/2009','01/01/2011':'12/01/2012']
这给了我“不可用的类型”,这给了我一个字符串
threeyrs=actdf['01/01/2009':'12/31/2009'],actdf['01/01/2011':'12/31/2012']
有方便的方法吗? dataFrame看起来像
Units date 2000-05-01 3041 2000-06-01 3079 2000-07-01 2455 2000-08-01 2671 2000-09-01 2220
I have a pandas DF with datetime index: this select works fine
threeyrs=actdf['01/01/2010':'12/31/2012']
but I'd like to get something like this (to exclude 2010):
threeyrs=actdf['01/01/2009':'12/01/2009','01/01/2011':'12/01/2012']
which gives me "unhashable type" and this gives me a string
threeyrs=actdf['01/01/2009':'12/31/2009'],actdf['01/01/2011':'12/31/2012']
Is there a convenient way? dataFrame looks like
Units date 2000-05-01 3041 2000-06-01 3079 2000-07-01 2455 2000-08-01 2671 2000-09-01 2220
原文:https://stackoverflow.com/questions/20502822
最满意答案
试着看看这是否有所不同:
$user = (clone) $this->getServiceLocator()->get('User');
如果您明确告知,服务管理器每次只会为您提供一个新实例
http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html
请注意有关共享服务的部分。 这将告诉服务管理器您每次都想要一个新的User对象,那么您将不需要像上面那样克隆该对象
'shared' => array( // Usually, you'll only indicate services that should _NOT_ be // shared -- i.e., ones where you want a different instance // every time. 'User' => false, ),
Try to see if this makes a difference:
$user = (clone) $this->getServiceLocator()->get('User');
The service manager will only provide you with a new instance each time if you specifically tell it to
http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html
Note the part about shared services. This would tell the service manager you want a new User object every time, then you will not need to clone the object as above
'shared' => array( // Usually, you'll only indicate services that should _NOT_ be // shared -- i.e., ones where you want a different instance // every time. 'User' => false, ),
相关问答
更多-
如何在tablegateway ZF2的JOIN ON子句中添加IN语句(How to add IN statement with JOIN ON clause in tablegateway ZF2)[2023-11-18]
我想你可以传递一个表达式来代替连接字符串: // $this->table = 'category'; $sql = $this->getSql(); $select = $sql->select(); $join = new Expression('user_category_subscriptions.category_id = category.id AND user_category_subscriptions.status IN (1,2,3,4)'); $select->join('user ... -
您引用的Zend Framework功能在v2.3中引入 : Zend\Db\Sql\Insert可以使用Select对象作为值源( INSERT INTO ... SELECT ) 我怀疑你使用的是旧版本。 您可以将v2.2.10中的 Zend\Db\Sql\Insert与v2.3.0进行比较,以查看为无效参数抛出的不同异常。 您应该将Zend Framework升级到v2.3或更高版本才能使用此功能。 The Zend Framework feature you're referencing was i ...
-
Zend\Db\Adapter\Driver\DriverInterface指定了一个getLastGeneratedValue()方法,所以推测这应该工作... $lastId = $this->adapter->getDriver()->getLastGeneratedValue(); The Zend\Db\Adapter\Driver\DriverInterface specifies a getLastGeneratedValue() method, so presumably this sh ...
-
您正尝试在适配器中绑定参数而不是在TableGateway中。 它可以通过多种方式完成,但是您发布的示例 $id = 123; $res = $adapter->query( "SELECT * FROM TABLE WHERE SOME_ID = ? AND STATUS = 1", [$id] ); var_dump($res->current()); 函数query()中有第二个参数 @param string|array|ParameterContainer $parametersOrQ ...
-
ZF2 tablegateway on select显示错误“未知列”(ZF2 tablegateway on select shows error “unknown column”)[2024-02-28]
问题是我没有正确配置tablegateway。 它是'用户'而不是'上传'。 'UploadTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setAr ... -
试试http://zf2-tutorial.localhost/public 如果可行,您可以更改vhosts文件中的以下条目 DocumentRoot "C:/xampp/htdocs/zf2-tutorial/public"
Try http://zf2-tutorial.localhost/public If that works you could change the following ... -
从csv文件加载时,ZF2 TableGateway重复值(ZF2 TableGateway repeating values when loading from csv file)[2022-05-27]
试着看看这是否有所不同: $user = (clone) $this->getServiceLocator()->get('User'); 如果您明确告知,服务管理器每次只会为您提供一个新实例 http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.html 请注意有关共享服务的部分。 这将告诉服务管理器您每次都想要一个新的User对象,那么您将不需要像上面那样克隆该对象 'shared' => a ... -
如何查看数据库查询的非常优雅的方式是使用zend-developer-tools。 如何使用它最简单的方法是通过将模块添加到composer.json文件来安装模块 ..... "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" } ], "require": { "php": ">=5.3.3", "zendframework/zend-developer-tools": "dev-mast ...
-
TableGateway从构造函数获取其适配器。 无论工厂在$this->tableGateway属性中创建TableGateway实例,都应将模拟适配器(或真正适配器,如果这是针对集成测试)传递给其构造函数。 TableGateway gets its adapter from constructor. Whatever factory creates TableGateway instance at your $this->tableGateway property, should pass your ...
-
如何在zf2中使用tablegateway执行联合查询?(How to execute union query in zf2 where i m using tablegateway?)[2021-10-27]
试试 - $select1 = new Select('table1'); [.... rest of the code ....] $select2 = new Select('table2'); [.... rest of the code ....] $select1->combine($select2); //This will create the required SQL union statement. 要获得两个表的计数,你必须使用一些SQL而不是tableGateway - $sq ...