我用大写字母表示矩阵,用小写字母表示向量.
我需要解决以下矢量线性不等式系统v:
min(rv - (u + Av), v - s) = 0
Run Code Online (Sandbox Code Playgroud)
哪里0是零矢量.
其中r是一个标量,u并且s是载体,以及A是一个矩阵.
定义z = v-s,B=rI - A,q=-u + Bs,我可以重写前面的问题作为线性互补问题,并希望能使用LCP求解器,例如openopt:
LCP(M, z): min(Bz+q, z) = 0
Run Code Online (Sandbox Code Playgroud)
或者,以矩阵表示法:
z'(Bz+q) = 0
z >= 0
Bz + q >= 0
Run Code Online (Sandbox Code Playgroud)
问题是我的方程系统很大.要创造A,我
A11,A12,A21,A22使用scipy.sparse.diagsA = scipy.sparse.bmat([[A11, A12], [A21, …考虑表单的数据框架
idnum start end
1993.1 17 1993-01-01 1993-12-31
1993.2 17 1993-01-01 1993-12-31
1993.3 17 1993-01-01 1993-12-31
Run Code Online (Sandbox Code Playgroud)
有start和end类型Date
$ idnum : int 17 17 17 17 27 27
$ start : Date, format: "1993-01-01" "1993-01-01" "1993-01-01" "1993-01-01" ...
$ end : Date, format: "1993-12-31" "1993-12-31" "1993-12-31" "1993-12-31" ...
Run Code Online (Sandbox Code Playgroud)
我想创建一个新的数据帧,而不是每行的每月观察,中间的每个月start和end(包括边界):
期望的输出
idnum month
17 1993-01-01
17 1993-02-01
17 1993-03-01
...
17 1993-11-01
17 1993-12-01
Run Code Online (Sandbox Code Playgroud)
我不确定month应该采用什么格式,我会在某些时候想要分组idnum,month以便对其余数据集进行回归. …
我有一个2比2的情节,我正在动态创建.在第一行我想绘制密度函数,在第二行CDF中.我想要
也就是说,垂直对齐的两个对象具有相同的x轴,并且两个水平对齐的图具有相同的y轴.
但是,sharex并sharey强制它们对于所有子图都是相同的.如何修复这种轴共享?我知道我可以手动为每个轴分配一个共享伙伴,但这不适用于下面的通用结构:
fig, axes = plt.subplots(nrows=2, ncols=2, sharex=True)
for i, lam in enumerate(lams):
axesNow = [axs[i] for axs in axes] # pick the ith column from axes
for i, Param.p in enumerate(pp):
axesNow[0].plot(somethingWithPDF)
axesNow[1].plot(somethingWithCDF)
for ax in axes.flatten(): ax.legend()
Run Code Online (Sandbox Code Playgroud)
我有一个results表格的数据框
TOTEXPPQ TOTEXPCQ FINLWT21
year quarter
13 1 9.183392e+09 5.459961e+09 1271559.398
2 2.907887e+09 1.834126e+09 481169.672
Run Code Online (Sandbox Code Playgroud)
我试图将所有(前两个)列除以最后一列.我的尝试是
weights = results.pop('FINLWT21')
results/weights
Run Code Online (Sandbox Code Playgroud)
但我明白了
ValueError: cannot join with no level specified and no overlapping names
Run Code Online (Sandbox Code Playgroud)
我没有得到:索引中有重叠的名称:
weights.head()
year quarter
13 1 1271559.398
2 481169.672
Run Code Online (Sandbox Code Playgroud)
是否有更好的方法来进行这种划分?我需要重置索引吗?
我有索引(一个数据帧year,foo),其中,我想选择的X最大观测foo其中year == someYear.
我的方法是
df.sort_index(level=[0, 1], ascending=[1, 0], inplace=True)
df.loc[pd.IndexSlice[2002, :10], :]
Run Code Online (Sandbox Code Playgroud)
但我明白了
KeyError: 'MultiIndex Slicing requires the index to be fully lexsorted tuple len (2), lexsort depth (0)'
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的排序变体(例如ascending = [0, 0]),但它们都导致了某种错误.
如果我只想要这xth行,我可以df.groupby(level=[0]).nth(x)在排序之后,但由于我想要一组行,所以效率不高.
选择这些行的最佳方法是什么?一些数据:
rank_int rank
year foo
2015 1.381845 2 320
1.234795 2 259
1.148488 199 2
0.866704 2 363
0.738022 2 319
Run Code Online (Sandbox Code Playgroud) 我有一系列datetime格式,需要更改1每个条目的日期.我想到了很多简单的解决方案,但它们都不适用于我.目前,唯一真正有效的是
它真的不是那么复杂,可以吗?有一个月的开始,但不幸的是offset,这在这里毫无用处.set()对于该方法似乎没有任何功能,并且当系列是列时,功能更少,而不是(部分)索引本身.
唯一相关的问题是这个,但那里使用的技巧在这里不适用.
当我想查看涉及缺失数据的数据时,我得到一个FloatingPointError.
import numpy as np
import pandas as pd
np.seterr(all='raise')
s = pd.Series([np.nan,np.nan,np.nan],index=[1,2,3]); print(s); print(s.head())
Run Code Online (Sandbox Code Playgroud)
我是最新版本的pandas,安装通过
conda install -f pandas
Run Code Online (Sandbox Code Playgroud)
之后pkill python和conda remove pandas.
这是回溯:
Out[4]: ---------------------------------------------------------------------------
FloatingPointError Traceback (most recent call last)
/home/xxx/.conda/envs/myenv2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
695 type_pprinters=self.type_printers,
696 deferred_pprinters=self.deferred_printers)
--> 697 printer.pretty(obj)
698 printer.flush()
699 return stream.getvalue()
/home/xxx/.conda/envs/myenv2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
381 if callable(meth):
382 return meth(obj, self, cycle)
--> 383 return _default_pprint(obj, self, cycle)
384 finally:
385 self.end_group()
/home/xxx/.conda/envs/myenv2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, …Run Code Online (Sandbox Code Playgroud) 我关注了Pandas Dataframe:
In [66]: hdf.size()
Out[66]:
a b
0 0.0 21004
0.1 119903
0.2 186579
0.3 417349
0.4 202723
0.5 100906
0.6 56386
0.7 6080
0.8 3596
0.9 2391
1.0 1963
1.1 1730
1.2 1663
1.3 1614
1.4 1309
...
186 0.2 15
0.3 9
0.4 21
0.5 4
187 0.2 3
0.3 10
0.4 22
0.5 10
188 0.0 11
0.1 19
0.2 20
0.3 13
0.4 7
0.5 5
0.6 1
Length: 4572, dtype: int64
Run Code Online (Sandbox Code Playgroud)
你看,从0到188和每个组中的b从某个值到某个值.并且作为指定的Z值,对a/b的出现次数.
如何从分组数据框中获取countour或heatmap图?
我有这个(要求?): …
当我想保存我的回归结果时
stargazer(regressions[[reg]], out=myFile, out.header=FALSE
Run Code Online (Sandbox Code Playgroud)
stargazer保持同时显示/打印结果到控制台.当我迭代几十个结果时,这会破坏我的概述和日志.有没有办法明确告诉stargazer不仅要将输出保存到文件中,还要不另外打印它?
我在stargazer_5.1.
我正在尝试使用statsmodels(sm)使HP过滤器工作.
这里的文档暗示模块sm.tsa已经存在0.6.1,但是我收到以下错误:
>>> import statsmodels as sm
>>> sm.__version__
'0.6.1'
>>> sm.tsa.filters.hp_filter.hpfilter()
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'tsa'
>>> sm.tsa
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'tsa'
Run Code Online (Sandbox Code Playgroud)
这是我的pip输出:
nat-oitwireless-inside-vapornet100-a-14423:prog2 foobar$ pip show statsmodels
---
Name: statsmodels
Version: 0.6.1
Location: /usr/local/lib/python2.7/site-packages/statsmodels-0.6.1-py2.7-macosx-10.9-x86_64.egg
Requires:
Run Code Online (Sandbox Code Playgroud)