所以我完全理解如何使用resample,但文档并没有很好地解释选项.
所以resample函数中的大多数选项都很简单,除了这两个:
因此,通过查看我在网上找到的尽可能多的示例,我可以看到规则,你可以做'D'一天,'xMin'几分钟,'xL'几毫秒,但这就是我能找到的.
对我怎么看到以下内容:'first',np.max,'last','mean',和'n1n2n3n4...nx'其中nx为每列索引的第一个字母.
那么在我缺少的文档中是否有某个地方显示了pandas.resample规则和输入的每个选项?如果是的话,因为我找不到它.如果不是,那么他们的选择是什么?
所以在numpy数组中有内置函数来获取对角线索引,但我似乎无法弄清楚如何从右上角而不是左上角开始对角线.
这是从左上角开始的常规代码:
>>> import numpy as np
>>> array = np.arange(25).reshape(5,5)
>>> diagonal = np.diag_indices(5)
>>> array
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
>>> array[diagonal]
array([ 0, 6, 12, 18, 24])
Run Code Online (Sandbox Code Playgroud)
所以如果我想要它返回,我该怎么用:
array([ 4, 8, 12, 16, 20])
Run Code Online (Sandbox Code Playgroud) 所以我试图通过运行以下代码来更新我的模型:
FooBar.objects.filter(something=True).update(foobar=F('foo__bar'))
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
FieldError: Joined field references are not permitted in this query
Run Code Online (Sandbox Code Playgroud)
如果F表达式不允许这样做...我怎样才能实现此更新?
鉴于这张票中的信息,我现在明白这是不可能的,永远不会在django中实现,但有没有办法实现这个更新?也许有一些解决方法?我不想使用循环,因为有超过1000万个FooBar对象,所以SQL比python快得多.
我有一个变量,我需要知道它是否是一个日期时间对象.
到目前为止,我一直在使用函数中的以下hack来检测datetime对象:
if 'datetime.datetime' in str(type(variable)):
print('yes')
Run Code Online (Sandbox Code Playgroud)
但是确实应该有一种方法可以检测出什么类型的物体.就像我能做的那样:
if type(variable) is str: print 'yes'
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点,除了将对象类型的名称转换为字符串并查看字符串是否包含'datetime.datetime'?
在Python中你有None单例,在某些情况下它的作用非常奇怪:
>>> a = None
>>> type(a)
<type 'NoneType'>
>>> isinstance(a,None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
Run Code Online (Sandbox Code Playgroud)
首先,<type 'NoneType'>显示None不是类型的,但也就是说NoneType.然而,当你跑步时isinstance(a,NoneType),它会回应一个错误:NameError: name 'NoneType' is not defined
现在,鉴于此,如果您有一个输入默认设置为None,并需要检查的函数,您将执行以下操作:
if variable is None:
#do something
else:
#do something
Run Code Online (Sandbox Code Playgroud)
我不能做以下事情的原因是什么:
if isinstance(variable,None): #or NoneType
#do something
else:
#do something
Run Code Online (Sandbox Code Playgroud)
我只是在寻找详细的解释,所以我可以更好地理解这一点
编辑:好的应用程序
让我们说我想使用, …
如果我想制作一条水平线,我会这样做:
<style>
#line{
width:100px;
height:1px;
background-color:#000;
}
</style>
<body>
<div id="line"></div>
Run Code Online (Sandbox Code Playgroud)
如果我想制作一条垂直线,我会这样做:
#line{
width:1px;
height:100px;
background-color:#000;
}
</style>
<body>
<div id="line"></div>
Run Code Online (Sandbox Code Playgroud)
曲线比较复杂,但可以使用border-radius和包装元素:
<style>
.curve{
width:100px;
height:500px;
border:1px #000 solid;
border-radius:100%;
}
#wrapper{
overflow:hidden;
width:40px;
height:200px;
}
</style>
<body>
<div id="wrapper">
<div class="curve"></div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
但我甚至无法理解如何产生波浪线!这甚至是远程可能只使用css(和javascript,因为它似乎有必要能够更容易地生成它们).
正如预期的那样,给出你的答案,没有办法在单一的CSS中做到这一点... javascript和jquery 100%可以为你的答案... 没有图像可以使用
我一直在寻找各处寻找一个合适的解释,它们都很简短... 你什么时候使用@api_view装饰器而不是基于类的视图与django rest框架应用程序
所以我有一些手机加速度计数据,我想基本上制作一个视频,看看手机的动作是什么样的.所以我使用matplotlib来创建数据的3D图形:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
import pickle
def pickleLoad(pickleFile):
pkl_file = open(pickleFile, 'rb')
data = pickle.load(pkl_file)
pkl_file.close()
return data
data = pickleLoad('/Users/ryansaxe/Desktop/kaggle_parkinsons/accelerometry/LILY_dataframe')
data = data.reset_index(drop=True)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xs = data['x.mean']
ys = data['y.mean']
zs = data['z.mean']
ax.scatter(xs, ys, zs)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
Run Code Online (Sandbox Code Playgroud)
现在时间很重要,实际上也是一个因素,我一次只能看到一个点,因为时间也是一个因素,它让我可以看到加速度计数据的进展!
我该怎么做才能使它成为实时更新图?
我唯一能想到的是拥有一个循环,逐行遍历并从行中生成图形,但这将打开这么多文件,因为我有数百万行,所以它会疯狂.
那么如何创建实时更新图?
我有一些数据,我想把它分成更小的组,保持一个共同的比例.我写了一个函数,它将输入两个数组并计算大小比例,然后告诉我可以将它分成多少组的选项(如果所有组的大小相同),这里是函数:
def cross_validation_group(train_data, test_data):
import numpy as np
from calculator import factors
test_length = len(test_data)
train_length = len(train_data)
total_length = test_length + train_length
ratio = test_length/float(total_length)
possibilities = factors(total_length)
print possibilities
print possibilities[len(possibilities)-1] * ratio
super_count = 0
for i in possibilities:
if i < len(possibilities)/2:
pass
else:
attempt = float(i * ratio)
if attempt.is_integer():
print str(i) + " is an option for total size with " + str(attempt) + " as test size and " + str(i - attempt) …Run Code Online (Sandbox Code Playgroud) 我有一个快速脚本,跟随光标有一个跟踪:
jQuery(document).ready(function(){
$(document).mousemove(function(e){
$('.fall').each(function(){
if ($(this).css("opacity") == 0){
$(this).remove();
};
});
t = (e.pageY - 10).toString() + 'px';
l = (e.pageX - 10).toString() + 'px';
$('.fall').css("margin_left",l);
$('.fall').css("margin_top",t);
var doit = '<div class="fall" style="position:fixed;margin-left:' + l + ';margin-top:' + t + ';">+</div>'
$('body').prepend(doit);
$('#status2').html(e.pageX +', '+ e.pageY);
$('.fall').animate({
marginTop: '+=50px',
opacity: 0
},1000);
});
});
Run Code Online (Sandbox Code Playgroud)
现在我想移除animate部件,并在鼠标不移动时使用以下内容:
$('.fall').each(function(){
$(this).fadeOut('slow');
$(this).remove()
});
Run Code Online (Sandbox Code Playgroud)
当鼠标移动速度超过一秒钟时,我无法弄清楚如何执行此操作.有任何想法吗?
谢谢,这是一个jsfiddle
python ×8
django ×2
javascript ×2
jquery ×2
numpy ×2
api ×1
arrays ×1
css ×1
datetime ×1
function ×1
graph ×1
html ×1
matplotlib ×1
mouseevent ×1
pandas ×1
python-2.7 ×1
python-3.x ×1
sql ×1
types ×1
view ×1