我试图从具有形状的数据框传递值到stats.friedmanchisquare.df(11,17)
这是什么样的工作,我(在这个例子中只为三排):
df = df.as_matrix()
print stats.friedmanchisquare(df[1, :], df[2, :], df[3, :])
Run Code Online (Sandbox Code Playgroud)
产量
(16.714285714285694, 0.00023471398805908193)
Run Code Online (Sandbox Code Playgroud)
但是,当我想要使用所有11行时, 代码行太长df.
首先,我尝试以下列方式传递值:
df = df.as_matrix()
print stats.friedmanchisquare([df[x, :] for x in np.arange(df.shape[0])])
Run Code Online (Sandbox Code Playgroud)
但我得到:
ValueError:
Less than 3 levels. Friedman test not appropriate.
Run Code Online (Sandbox Code Playgroud)
其次,我也尝试不将它转换为矩阵形式,将其作为DataFrame(这对我来说很理想),但我想这还不支持,或者我做错了:
print stats.friedmanchisquare([row for index, row in df.iterrows()])
Run Code Online (Sandbox Code Playgroud)
这也给了我错误:
ValueError:
Less than 3 levels. Friedman test not appropriate.
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:基于参数传递给stats.friedmanchisquare的正确方法是什么df?(甚至使用其df.as_matrix()代表)
您可以在此处以csv格式下载我的数据帧并使用以下方式阅读: …
我现在正在使用Python 3.5解释器,发现了非常有趣的行为:
>>> (1,2,3,"a",*("oi", "oi")*3)
(1, 2, 3, 'a', 'oi', 'oi', 'oi', 'oi', 'oi', 'oi')
>>> [1,2,3,"a",*range(10)]
[1, 2, 3, 'a', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> ('aw','aw',*range(10),*(x**2 for x in range(10)))
('aw', 'aw', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 4, 9, 16, 25, 36, 49, 64, 81)
>>> {"trali":"vali", **dict(q=1,p=2)}
{'q': 1, 'p': 2, 'trali': 'vali'}
>>> {"a",1,11,*range(5)}
{0, 1, 2, 3, 4, 11, 'a'}
Run Code Online (Sandbox Code Playgroud)
尽管我有多年的Python经验,但我从未在文档和示例中以及任何源代码中看到过这种情况.我发现它非常有用. …
我有一个变量say,column_name.我想更新名称保存在变量column_name中的列.
例如:我有一个表格列为:a,b,c,...,z.column_name存储这些值中的任何一个.所以我想更新保存在变量column_name中的特定列.
谢谢Anuj
我想知道这是否可能:
def someFunction():
return list(range(5))
first, rest = someFunction()
print(first) # 0
print(rest) # [1,2,3,4]
Run Code Online (Sandbox Code Playgroud)
我知道可以通过以下3行完成:
result = someFunction()
first = result[0]
rest = result[1:]
Run Code Online (Sandbox Code Playgroud) 我正在编写一个 Python 程序来为沿 3D 曲线的切线设置动画。但是,我的切线没有移动。我认为问题是
line.set_data(np.array(Tangent[:,0]).T,np.array(Tangent[:,1]).T)
在,animate(i)但我想不通。任何帮助将不胜感激。以下是代码。
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import matplotlib
matplotlib.use( 'tkagg' )
plt.style.use('seaborn-pastel')
fig = plt.figure()
ax = plt.axes(projection='3d')
ax = plt.axes(projection='3d')
# Data for a three-dimensional line
zline = np.linspace(0, 15, 1000)
xline = np.sin(zline)
yline = np.cos(zline)
ax.plot3D(xline, yline, zline, 'red')
def curve(t):
return [np.sin(t),np.cos(t),t]
def vector_T(t):
T = [np.cos(t),-np.sin(t),1]
return T/np.linalg.norm(T)
len = 2
def tangent_line(t):
P = np.add(curve(t),len*vector_T(t)) …Run Code Online (Sandbox Code Playgroud) 我没有找到更好的方法来在标题中表达这个问题.如果可以,请编辑.
我有一个这样的列表列表:
a = [['a','b'],[1,2]]
Run Code Online (Sandbox Code Playgroud)
现在,我想要一个能够吐出所有可能组合的函数:
[['a',1],['a',2],['b',1],['b',2]]
Run Code Online (Sandbox Code Playgroud)
预先知道a中的列表的数量,也不预先知道每个子列表的长度,但所有出现的组合应该包含每个子列表中的1个项目.
我有一个包含从数据库查询生成的元组的列表,它看起来像这样.
[(item1, value1), (item2, value2), (item3, value3),...]
Run Code Online (Sandbox Code Playgroud)
元组将是混合长度,当我打印输出时它将看起来像这样.
item1=value1, item2=value2, item3=value3,...
Run Code Online (Sandbox Code Playgroud)
我已经找了一段时间试图找到一个解决方案,但.join()我找不到适用于这种情况的解决方案.
清理文字:
如何创建添加upp的m = 5个随机数,比如n = 100.但是,第一个随机数是10 <x1 <30,第二个随机nr是5 <x2 <20,第三个随机nr是10 <x3 <25,等等.所以这五个随机数加起来为100.我可以创建这些约束的五个数字吗?
.
[[
相关问题A1):创建五个随机数加起来为100的标准方法是在[0,100]之间采样四个数字,并添加边界0和100,然后对这六个数字[0,x1,x2, X3,x4,100].我寻求的五个随机数是增量.那是,
100 - x[4] = delta 5
x[4]- x[3] = delta 4
x[3]- x[2] = delta 3
x[2]- x[1] = delta 2
x[1] - 0 = delta 1
Run Code Online (Sandbox Code Playgroud)
这五个增量现在将加起来为100.例如,它们可能是0,1,2,7,90.以下是一些解决此问题的代码:
total_sum = 100
n = 5
v = numpy.random.multinomial(total_sum, numpy.ones(n)/n)
Run Code Online (Sandbox Code Playgroud)
]]
.
对于我的问题,我不能允许宽间隔发生,上面的最大扩展是90-7 = 83这太宽.所以,我必须指定更严格的传播,比如[10,30].这意味着最大的随机数是30,这不允许大的点差,如83.
.
[[
相关问题A2):创建具有相同边界的10 个数字的部分解决方案,10 <x_i <30,加起来为100就像这样:只是在A1中做,但是将下边界10添加到增量.所以我得到了我想要的五个随机数:
100 - x[4] = delta 5 + 10
x[4]- x[3] = delta 4 …Run Code Online (Sandbox Code Playgroud) 我想用可选参数测试函数调用.
这是我的代码:
list_get()
list_get(key, "city", 0)
list_get(key, 'contact_no', 2, {}, policy)
list_get(key, "contact_no", 0)
list_get(key, "contact_no", 1, {}, policy, "")
list_get(key, "contact_no", 0, 888)
Run Code Online (Sandbox Code Playgroud)
由于可选参数,我无法对其进行参数化,因此我为每个api调用编写了单独的测试函数pytest.
我相信应该有更好的方法来测试这个.
这个问题在这里是有用的,但我是略有不同.
我想在这里做一些简单的事情,我有一个numpy矩阵A,我只想创建另一个与A形状相同的numpy矩阵B,但是我想要创建B来完成它怎么办?谢谢.numpy.random.randn()
python ×9
numpy ×3
list ×2
algorithm ×1
animation ×1
arrays ×1
django ×1
matplotlib ×1
pandas ×1
pep448 ×1
probability ×1
pytest ×1
python-3.x ×1
random ×1
scipy ×1
statistics ×1
tuples ×1