我想以设置func_doc
(作为表达)内 def
.
def f():
'''My function help''' #Set the docstring
def g():
"My function " + "help" # An expression, so not read as a docstring
# can I put something here to set the docstring as an expression?
g.func_doc # is None
g.func_doc = "My function " + "help" # This works
Run Code Online (Sandbox Code Playgroud)
这可能吗?
(我可以考虑这样做的两个原因:从模块导入函数(并且您也想导入文档字符串)和使用词法分析器.)
A = 200
B = -140
C = 400
D = -260
if A < 0:
v1 = 0
else:
v1 = A
if B < 0:
v2 = 0
else:
v2 = B
if C < 0:
v3 = 0
else:
v3 = C
if D < 0:
v4 = 0
else:
v4 = C
Run Code Online (Sandbox Code Playgroud)
上述代码结构的简写实现是什么?有没有更好/优雅/方便的方法来做到这一点?
我正在尝试创建一个类似于这些的简单立体太阳路径图:http: //wiki.naturalfrequency.com/wiki/Sun-Path_Diagram
我能够旋转极坐标图并将刻度设置为90.如何反转y轴?目前轴从0> 90,我如何将轴反转为90> 0来表示方位角?
我试过了:
ax.invert_yaxis()
ax.yaxis_inverted()
Run Code Online (Sandbox Code Playgroud)
此外,我将如何创建立体投影而不是等距?
我的代码:
import matplotlib.pylab as plt
testFig = plt.figure(1, figsize=(8,8))
rect = [0.1,0.1,0.8,0.8]
testAx = testFig.add_axes(rect,polar=True)
testAx.invert_yaxis()
testAx.set_theta_zero_location('N')
testAx.set_theta_direction(-1)
Azi = [90,180,270]
Alt= [0,42,0]
testAx.plot(Azi,Alt)
plt.show()
Run Code Online (Sandbox Code Playgroud)
目前我的代码似乎没有正确绘制线条,我是否需要将角度或度数转换为其他东西?
任何帮助是极大的赞赏.
当创建具有 MultiIndex 列的 DataFrame 时,似乎无法使用诸如df[df["AA"]>0.0]
. 例如:
import pandas as pd
import numpy as np
dates = np.asarray(pd.date_range('1/1/2000', periods=8))
_metaInfo = pd.MultiIndex.from_tuples([('AA', '[m]'), ('BB', '[m]'), ('CC', '[s]'), ('DD', '[s]')], names=['parameter','unit'])
df = pd.DataFrame(randn(8, 4), index=dates, columns=_metaInfo)
print df[df['AA']>0.0]
Run Code Online (Sandbox Code Playgroud)
df["AA"]>0.0 的结果是一个索引的 DataFrame iso a Timeseries。这可能会导致崩溃。
当使用相同的metaInfo作为行的索引时,情况有所不同:
df1 = pandas.DataFrame(np.random.randn(4, 6), index=_metaInfo)
print df1[df1["AA"]>0.0]
Run Code Online (Sandbox Code Playgroud)
产生:
[ 1.13268106 -0.06887761 0.68535054 2.49431163 -0.29349413 0.34772553]
Run Code Online (Sandbox Code Playgroud)
它们是 AA 行大于零的元素。这仅给出 AA 行的值,而不给出 DataFrame 的其他列的值。
有解决方法吗?我是否试图做一些我不应该做的事情?
我在比较两个DatetimeIndex
不同长度的问题时遇到了一个问题assert
,如下所示:
In [1]: idx1 = pd.date_range('2010-01-01','2010-12-31',freq='D')
In [2]: idx2 = pd.date_range('2010-01-01','2010-11-01',freq='D')
In [3]: assert (idx1 == idx2).all()
Run Code Online (Sandbox Code Playgroud)
我收到错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-17-ad2cfd6d11c2> in <module>()
----> 1 assert (idx1 == idx2).all()
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.10.1.dev_dcd9df7-py2.7-macosx-10.8-x86_64.egg/pandas/tseries/index.pyc in wrapper(self, other)
75 result = func(other)
76
---> 77 return result.view(np.ndarray)
78
79 return wrapper
AttributeError: 'NotImplementedType' object has no attribute 'view'
Run Code Online (Sandbox Code Playgroud)
如果没有实现,这是好的,但有没有一些熊猫这样做的方法?
注意: 我已成功使用以下内容:
In [3]: assert list(idx1) == list(idx2)
Run Code Online (Sandbox Code Playgroud)
所以,以下也有效:
In [3]: assert list(df.index) == list(testindex) …
Run Code Online (Sandbox Code Playgroud) 我有:
tuple1 = token1, token2
tuple2 = token2, token1
for tuple in [tuple1, tuple2]:
if tuple in dict:
dict[tuple] += 1
else:
dict[tuple] = 1
Run Code Online (Sandbox Code Playgroud)
但是,元组1和元组2都得到相同的计数.什么是一种方法来散列一组2件事,这样的秩序很重要?
我有一个多级数据框df
:
>>> df
sales cash
STK_ID RPT_Date
000568 20120630 51.926 42.845
20120930 80.093 57.488
000596 20120630 22.278 18.247
20120930 32.585 26.177
000799 20120630 9.291 6.513
20120930 14.784 8.157
Run Code Online (Sandbox Code Playgroud)
我想得到sub_level索引的值列表'STK_ID'
,它将返回一个列表['000568','000596','000799']
.
是否有任何直接的功能(不使用reset_index
和获取列值)?
所以我一直在制作这个程序一段时间.我已经浏览了整个互联网,但我找不到任何解决方案.每当我在arr [i] .question和arr [i] .answer中输入我的输入时,它说我的问题是错的,而我没有回答这个问题.我尝试过使用cin.ignore(),cin.clear()和cin.sync().我可能一直在错误的地方使用它们,但我不确定.我可能会感到困惑,所以只需查看代码即可.
这是输入格式.
cin >> count;
cin.ignore();
for(int i =0; i < count; i++){
cout << "Enter the question.\n" << endl;
//enter the question
getline(cin, arr[i].question);
cin.ignore();
cout << "Enter the answer.\n" << endl;
//enter the answer
getline (cin, arr[i].answer);
cin.ignore();
}
Run Code Online (Sandbox Code Playgroud)
这是输出格式来测验你.
for(int j =0; j < count; j++){
cout << "\n" << arr[j].question << endl;
getline(cin, userguess);
if(arr[j].answer.compare(userguess) !=0){
cout << "Wrong. Keep trying!\n";
incorrect++;
total++;
}
if(arr[j].answer.compare(userguess) ==0){
cout << "Nice job. Keep it …
Run Code Online (Sandbox Code Playgroud) 我有一个.sh文件,如下所示:
ruby one.rb
ruby two.rb
ruby three.rb
ruby four.rb
ruby five.rb
ruby six.rb
ruby seven.rb
ruby eight.rb
Run Code Online (Sandbox Code Playgroud)
这样做是逐个运行ruby文件.我将如何开始联合发布前四个,并且在前四个完成后立即抓住下一组.不知道如何处理这个,任何建议表示赞赏.我现在想避免使用rake并继续使用shell.
我试图将几个主要包含NaN的列连接到一个,但这里只是一个例子:
2013-06-18 21:46:33.422096-05:00 A NaN
2013-06-18 21:46:35.715770-05:00 A NaN
2013-06-18 21:46:42.669825-05:00 NaN B
2013-06-18 21:46:45.409733-05:00 A NaN
2013-06-18 21:46:47.130747-05:00 NaN B
2013-06-18 21:46:47.131314-05:00 NaN B
Run Code Online (Sandbox Code Playgroud)
这可能会持续3或4或10列,始终为1 pd.notnull()
,其余为NaN.
我想以最快的方式将这些连接成1列.我怎样才能做到这一点?