DataFrame我正在尝试为我正在处理的一些自定义数据编写一个继承 pandas 类的类。
class EquityDataFrame(DataFrame):
def __init__(self, *args, **kwargs):
DataFrame.__init__(self, *args, **kwargs)
def myfunc1(self,...)
... # does something
def myfunc2(self, ...)
... # does something
Run Code Online (Sandbox Code Playgroud)
在 PyCharm 中,我收到以下有关类名称的警告EquityDataFrame:
Class EquityDataFrame must implement all abstract methods
This inspection detects when there aren't all abstract properties/methods defined in the subclass
Run Code Online (Sandbox Code Playgroud)
我尝试用谷歌搜索,但找不到此警告的有用描述。有人可以帮我看看这个警告是什么意思吗?
在阅读有关类的 Cython 文档后有一个基本问题,但我想弄清楚。以下是Cython 文档中的示例代码:
cdef class Rectangle:
cdef int x0, y0
cdef int x1, y1
def __init__(self, int x0, int y0, int x1, int y1):
self.x0 = x0; self.y0 = y0; self.x1 = x1; self.y1 = y1
cpdef int area(self):
cdef int area
area = (self.x1 - self.x0) * (self.y1 - self.y0)
if area < 0:
area = -area
return area
Run Code Online (Sandbox Code Playgroud)
为什么__init__前面是defand 而不是cdefor cpdef?
我意识到有一个__cinit__函数,但是不应该cpdef __init__使__init__ …
我有一个 MATLAB 订阅,我读到 MATLAB 使用英特尔 MKL 库,但我不确定在哪里可以找到与英特尔 MKL 库相对应的所有 DLL/文件。我可以在文档中找到任何提到它们位置的地方。
谢谢
我想检查是否有任何预先存在的把戏na.locf(从zoo包装),rle并inverse.rle在RCpp?
我写了一个循环来实现,例如我做了na.locf(x, na.rm=FALSE, fromLast=FALSE)如下的实现:
#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
NumericVector naLocf(NumericVector x) {
int n=x.size();
for (int i=1;i<n;i++) {
if (R_IsNA(x[i]) & !R_IsNA(x[i-1])) {
x[i]=x[i-1];
}
}
return x;
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道,因为这些是非常基本的功能,有人可能已经RCpp以更好的方式实现它们(可能是避免循环)或更快的方式?
假设我有以下矩阵:
testM <- as.matrix(read.table(textConnection("
1 5 4 1 3 2
2 1 5 4 1 3
2 2 1 5 4 1
3 2 2 1 5 4
1 3 2 2 1 5
4 1 3 2 2 1
1 5 4 1 3 2
2 1 5 4 1 3
2 2 1 5 4 1
3 2 2 1 5 4
1 3 2 2 1 5
4 1 3 2 2 1
")))
Run Code Online (Sandbox Code Playgroud)
该矩阵有列名V1于 …
Cython 新手。setup.py我在一个名为将另一个文件编译到的文件中使用以下代码片段Cython(这是由 SO 用户向我建议的):
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension('func1', ['util/func1_pc.py'],)]
setup(
name="Set 1 of Functions",
cmdclass={'build_ext': build_ext},
ext_modules=ext_modules
)
Run Code Online (Sandbox Code Playgroud)
我将其编译为python setup.py build_ext --inplace. 这会将我的文件 at编译util/func1_pc.py到.func1.pydsetup.py
假设我现在有两个文件:util/funct1_pc.py和util/funct2_pc.py. 有人可以建议如何修改上面的代码片段来生成func1.pyd和func2.pyd生成它们吗?
谢谢。
假设我有一个pandas数据帧,其列值为datetime64[ns].
Out[204]:
0 2015-03-20 00:00:28
1 2015-03-20 00:01:44
2 2015-03-20 00:02:55
3 2015-03-20 00:03:39
4 2015-03-20 00:04:32
5 2015-03-20 00:05:52
6 2015-03-20 00:06:36
7 2015-03-20 00:07:44
8 2015-03-20 00:08:56
9 2015-03-20 00:09:47
Name: DateTime, dtype: datetime64[ns]
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法将它们转换成最后一分钟后的时间?即我想要以下内容:
Out[204]:
0 2015-03-20 00:01:00
1 2015-03-20 00:02:00
2 2015-03-20 00:03:00
3 2015-03-20 00:04:00
4 2015-03-20 00:05:00
5 2015-03-20 00:06:00
6 2015-03-20 00:07:00
7 2015-03-20 00:08:00
8 2015-03-20 00:09:00
9 2015-03-20 00:10:00
Name: DateTime, dtype: datetime64[ns]
Run Code Online (Sandbox Code Playgroud)
我写了一个复杂的代码,首先将它们转换为字符串,然后提取它们的三个部分00:09:47,将它们转换为整数,然后除非最后一部分(秒)已经00,我将最后一部分(秒)00 …
假设我有x和y与权重向量的载体wgt.我可以y = a x^3 + b x^2 + c x + d使用np.polyfit如下拟合三次曲线():
y_fit = np.polyfit(x, y, deg=3, w=wgt)
Run Code Online (Sandbox Code Playgroud)
现在,假设我想要做的又发作了,但是这一次,我想拟合通过0(即y = a x^3 + b x^2 + c x,d = 0),我怎么能(即指定一个特定的系数,d在这种情况下)是零?
谢谢
我想试用C#进行通用编程(而不是Web开发).我在Windows环境中编程,但我想避免专门针对Windows(.NET)进行编码,因为我希望保持选项打开以便将来迁移到Linux.
C#.NET中是否有任何特定的库在C#Mono中无法用于通用编程工作(对Windows Forms,Silverlight和类似的东西不感兴趣)?
是否有任何互联网链接的东西/功能,提供一个适用于C#.NET的列表不适用于C#Mono,反之亦然?我在谷歌本身并没有发现任何东西.
注意:我会对具体答案感兴趣,而不是更好或更差的意见(谢谢!)
假设有一个@property定义了的类:
class MyClass:
...
@property
def this_is_a_property(self):
return self.some_thing
...
def this_is_a_function(self, x):
...
return other_thing
Run Code Online (Sandbox Code Playgroud)
通常,要检查属性是否是函数,我可以isfunction从inspect模块中使用.
import inspect
if inspect.isfunction(MyClass.__dict__['this_is_a_function']):
print('this_is_a_function',' is a function')
Run Code Online (Sandbox Code Playgroud)
我该property怎么检查?似乎没有任何inspect.isproperty功能.
python ×4
python-3.x ×3
cython ×2
pandas ×2
r ×2
rcpp ×2
c# ×1
distutils ×1
intel-mkl ×1
matlab ×1
mono ×1
numpy ×1
properties ×1
setuptools ×1