我有numpy,statsmodel,pandas和scipy(我认为)
如何计算p值的z得分,反之亦然?
例如,如果我的ap值为0.95,我应该得到1.96作为回报.
我在scipy中看到了一些函数,但它们只在数组上运行z测试.
时间序列分解是将时间序列数据集分成三个(或更多)分量的方法.例如:
x(t) = s(t) + m(t) + e(t)
Run Code Online (Sandbox Code Playgroud)
哪里
t is the time coordinate
x is the data
s is the seasonal component
e is the random error term
m is the trend
Run Code Online (Sandbox Code Playgroud)
哪一个使用math.pow或**运算符更有效?我什么时候应该使用另一个?
到目前为止我知道x**y可以返回一个int或者float如果你使用十进制函数pow将返回一个浮点数
import math
print math.pow(10, 2)
print 10. ** 2
Run Code Online (Sandbox Code Playgroud) 我知道如何在R中这样做.但是,pandas中是否有任何函数将数据帧转换为包含两个方面共同计数的nxn共生矩阵.
例如矩阵df:
import pandas as pd
df = pd.DataFrame({'TFD' : ['AA', 'SL', 'BB', 'D0', 'Dk', 'FF'],
'Snack' : ['1', '0', '1', '1', '0', '0'],
'Trans' : ['1', '1', '1', '0', '0', '1'],
'Dop' : ['1', '0', '1', '0', '1', '1']}).set_index('TFD')
print df
>>>
Dop Snack Trans
TFD
AA 1 1 1
SL 0 0 1
BB 1 1 1
D0 0 1 0
Dk 1 0 0
FF 1 0 1
[6 rows x 3 columns]
Run Code Online (Sandbox Code Playgroud)
会屈服:
Dop …Run Code Online (Sandbox Code Playgroud) 我是熊猫新手.计算大熊猫RSI指标中相对强度部分的最佳方法是什么?到目前为止,我得到以下内容:
from pylab import *
import pandas as pd
import numpy as np
def Datapull(Stock):
try:
df = (pd.io.data.DataReader(Stock,'yahoo',start='01/01/2010'))
return df
print 'Retrieved', Stock
time.sleep(5)
except Exception, e:
print 'Main Loop', str(e)
def RSIfun(price, n=14):
delta = price['Close'].diff()
#-----------
dUp=
dDown=
RolUp=pd.rolling_mean(dUp, n)
RolDown=pd.rolling_mean(dDown, n).abs()
RS = RolUp / RolDown
rsi= 100.0 - (100.0 / (1.0 + RS))
return rsi
Stock='AAPL'
df=Datapull(Stock)
RSIfun(df)
Run Code Online (Sandbox Code Playgroud)
我到目前为止做得对吗?我对方程的不同部分有困难,你可以将向上和向下计算分开
所以我使用了一个空的数据帧
df=data[['ID','Matrix','Name','Country', 'Units']]
df['Value']=''
Run Code Online (Sandbox Code Playgroud)
我用这样的代码填充它,它找到包含'Good','Bad'值的字符串df.Matrix并用以下值填充它们sch[i]:
df.loc[df.Matrix.str.contains('Good'),'Value'] = sch[2]
df.loc[df.Matrix.str.contains('Bad'),'Value'] = sch[6]
df.loc[df.Matrix.str.contains('Excellent'),'Value'] = sch[8]
Run Code Online (Sandbox Code Playgroud)
我遇到了一堆像这两个不同的错误:
C:\Python33\lib\site-packages\pandas\core\strings.py:184: UserWarning: This pattern has match groups. To actually get the groups, use str.extract.
" groups, use str.extract.", UserWarning)
C:\Users\0\Desktop\python\Sorter.py:57: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
df.loc[df.Matrix.str.contains('Bad'),'Value'] = sch[6]
Run Code Online (Sandbox Code Playgroud)
到目前为止,我正在使用压缩代码
pd.options.mode.chained_assignment = None
Run Code Online (Sandbox Code Playgroud)
如果我不压制错误消息,我将得到大约20个错误消息.是否有其他格式我可以更改数据,以便我不会收到错误消息?
我使用python 3和pandas 0.131如果它有帮助
是否有一个pandas函数来转换此数据,因此它将列显示为a,b,c,d,e或数据字段内的任何内容,并且行计算有多少字母.
import pandas as pd
trans = pd.read_table('output.txt', header=None, index_col=0)
print trans
>>>
1 2 3 4
0
11 a b c NaN
666 a d e NaN
10101 b c d NaN
1010 a b c d
414147 b c NaN NaN
10101 a b d NaN
1242 d e NaN NaN
101 a b c d
411 c d e NaN
444 a b c NaN
Run Code Online (Sandbox Code Playgroud)
相反,我希望输出是这样的:
a b c d e
0
11 1 1 1 NaN …Run Code Online (Sandbox Code Playgroud) 在熊猫中实施Apriori算法的最佳方法是什么?到目前为止,我一直坚持转换使用for循环提取模式.从for循环开始的一切都不起作用.在熊猫中有没有矢量化的方法呢?
import pandas as pd
import numpy as np
trans=pd.read_table('output.txt', header=None,index_col=0)
def apriori(trans, support=4):
ts=pd.get_dummies(trans.unstack().dropna()).groupby(level=1).sum()
#user input
collen, rowlen =ts.shape
#max length of items
tssum=ts.sum(axis=1)
maxlen=tssum.loc[tssum.idxmax()]
items=list(ts.columns)
results=[]
#loop through items
for c in range(1, maxlen):
#generate patterns
pattern=[]
for n in len(pattern):
#calculate support
pattern=['supp']=pattern.sum/rowlen
#filter by support level
Condit=pattern['supp']> support
pattern=pattern[Condit]
results.append(pattern)
return results
results =apriori(trans)
print results
Run Code Online (Sandbox Code Playgroud)
当我插入支持3时
a b c d e
0
11 1 1 1 0 0
666 1 0 0 1 1
10101 …Run Code Online (Sandbox Code Playgroud) 我想用scikit-image做一些光学标记识别.我正在寻找2个功能
可以说我的图像看起来像这样:
我检测它的方法是使用滤镜来清理图像:(对filter模块中的噪声斑点进行双边和高斯滤波)
然后我会用在一个灰度缩放color模块第三我会使用Canny边缘检测器在filter模块
我试图找出我用什么来按颜色过滤细胞所以我可以分开红色和蓝色?
我猜有用于Hues公司,饱和度和亮度或RGB一些功能,可用于过滤掉特定的颜色或一些东西,可以被用来k-means从scikit learn过滤数据
其次是如何将此图像转换为numpy数组/ pandas数据帧,如下所示:
[[1,2,0,2,0]
[0,1,1,0,1]
[0,0,1,2,0]]
Run Code Online (Sandbox Code Playgroud)
其中红色为1,蓝色为2,白色为0.我看到有些人放下了一条线,但不知道它叫什么或是否在sk-image中可用.
python ×10
pandas ×6
statistics ×2
built-in ×1
dataframe ×1
finance ×1
math ×1
numpy ×1
pow ×1
scikit-image ×1
sum ×1
time-series ×1