考虑以下三个DataFrame
:
df1 = pd.DataFrame([[1,2],[4,3]])
df2 = pd.DataFrame([[1,.2],[4,3]])
df3 = pd.DataFrame([[1,'a'],[4,3]])
Run Code Online (Sandbox Code Playgroud)
以下是第二列的类型DataFrame
:
In [56]: map(type,df1[1])
Out[56]: [numpy.int64, numpy.int64]
In [57]: map(type,df2[1])
Out[57]: [numpy.float64, numpy.float64]
In [58]: map(type,df3[1])
Out[58]: [str, int]
Run Code Online (Sandbox Code Playgroud)
在第一种情况下,所有int
的都是铸造的numpy.int64
.精细.在第三种情况下,基本上没有铸造.但是,在第二种情况下,整数(3
)被转换为numpy.float64
; 可能因为其他数字是浮点数.
我怎样才能控制铸件?在第二种情况下,我希望有[float64, int64]
或[float, int]
作为类型.
使用可调用打印功能可以有一个替代方案来显示在这里.
def printFloat(x):
if np.modf(x)[0] == 0:
return str(int(x))
else:
return str(x)
pd.options.display.float_format = printFloat
Run Code Online (Sandbox Code Playgroud) 我vscode
在使用atom
了很长一段时间后正在探索.我缺少的一件事就是相当于可爱的包装advanced-open-file
.在vscode中有类似的东西吗?
我找到了advanced-new-file
扩展名,但它只对新文件有用.我希望能够快速打开来自我本地文件(不仅是工作区)的文件.
编辑:我找到了选项workbench.action.quickOpen
; 但它不允许从整个文件系统中打开文件.
受到这篇伟大帖子的启发,我正在尝试使用org-mode
和babel
发出查询的组合elasticsearch
.例如,计算索引中的条目数:
#+BEGIN_SRC sh
curl -XGET 'http://my.uri.example:8080/index/_count'
#+END_SRC
Run Code Online (Sandbox Code Playgroud)
C-c C-c
当点在块中时,可以使用上面的代码进行评估.1
另一方面,可以在组织文档中定义宏.我的问题是:是否可以定义一个宏
#+MACRO: live-db http://my.uri.example:8080
Run Code Online (Sandbox Code Playgroud)
并重写代码块如下:
#+BEGIN_SRC sh
curl -XGET '{{{live-db}}}/index/_count'
#+END_SRC
Run Code Online (Sandbox Code Playgroud)
开箱即用,对我来说,它没有用......似乎babel
在评估块之前没有扩展宏.想法?
现在,一旦我了解到我可以使用es-mode
,我就不会对我的问题进行微调.考虑以下两个请求:
#+BEGIN_SRC es :url http://mu.uri.stage:8080
GET /users/_search?pretty
{
"query": {
"match_all":{}
}
}
#+END_SRC
Run Code Online (Sandbox Code Playgroud)
和
#+BEGIN_SRC es :url http://mu.uri.live:8080
GET /users/_search?pretty
{
"query": {
"match_all":{}
}
}
#+END_SRC
Run Code Online (Sandbox Code Playgroud)
它们只是URL不同.我想定义两个宏:
#+MACRO staging http://my.uri.stage:8080
#+MACRO live http://my.uri.live:8080
Run Code Online (Sandbox Code Playgroud)
然后使用宏作为块的变量.可能吗?
1确保启用评估sh
.添加如下内容:
(org-babel-do-load-languages
'org-babel-load-languages …
Run Code Online (Sandbox Code Playgroud) 我试图用Python记录一个包.目前我有以下目录结构:
.
??? project
??? _build
? ??? doctrees
? ??? html
? ??? _sources
? ??? _static
??? conf.py
??? index.rst
??? __init__.py
??? make.bat
??? Makefile
??? mod1
? ??? foo.py
? ??? __init__.py
??? mod2
? ??? bar.py
? ??? __init__.py
??? _static
??? _templates
Run Code Online (Sandbox Code Playgroud)
这棵树是射击的结果sphinx-quickstart
.在conf.py
我没有注释sys.path.insert(0, os.path.abspath('.'))
,我有extensions = ['sphinx.ext.autodoc']
.
我index.rst
是:
.. FooBar documentation master file, created by
sphinx-quickstart on Thu Aug 28 14:22:57 2014.
You can adapt …
Run Code Online (Sandbox Code Playgroud) 下列:
timeit print("foo")
Run Code Online (Sandbox Code Playgroud)
返回类似于:100000 loops, best of 3: 2.35 µs per loop
.我猜这100000
与number
论证有关timeit
.我不明白什么是best of 3
手段,什么是使用的时间单位?在这种情况下它可能是微秒,但我也看到us
和ns
作为单位; 但是,我在文档中找不到解释.
由于谷歌字符串包含$
(美元符号)是有问题的,我无法找到以下输出的任何解释:
{Cos[tmp$132923 + \[Phi]],
Sin[tmp$132926 + \[Phi]],
\[Phi]
}
Run Code Online (Sandbox Code Playgroud)
什么tmp$xxxx
意思?
在`book2.nb'中我定义了以下函数:
g[i_, j_] := {
f1[i, t, f2[b, j], p][[1]],
f1[i, t, f2[b, j], p][[2]],
f3[i, t, p]
}
Run Code Online (Sandbox Code Playgroud)
凡f1,f2,f3
在另一个笔记本电脑都被定义book1.nb
,这是初始化和工作的罚款.此外,f1
返回一个列表,并且b
是一个定义并激活的列表.
现在,当我调用时,g[1,1]
我得到一个类似于上面引用的输出 - 用这个tmp$
.然而,如果我试图绘制g
它完美的工作(使用ParametricPlot3D[g[1, 1], {t, 0, 1}, {p, 0, 2 Pi}]
).但是,如果我尝试定义变量
V= {
f1[1, t, f2[b, 1], p][[1]],
f1[1, t, f2[b, 1], p][[2]],
f3[1, t, p]
}
Run Code Online (Sandbox Code Playgroud)
我 …
在我写的一个模块中,我有很多(用于开发和测试阶段)Print["Messages"]
.我有两个问题:
假设我有一个时间戳列datetime
的pandas.DataFrame
.例如,时间戳以秒为单位分辨率.我想在10分钟[1]水桶/垃圾箱中装箱/垃圾箱.我知道我可以datetime
将整数时间戳表示为整数,然后使用直方图.有更简单的方法吗?内置的东西pandas
?
[1] 10分钟只是一个例子.最终,我想使用不同的分辨率.
使用时click
我知道如何定义多项选择选项。我也知道如何将选项设置为必需选项。但是,我怎么能表明一个选项B
,只需要在设置选项的值A
是foo
?
下面是一个例子:
import click
@click.command()
@click.option('--output',
type=click.Choice(['stdout', 'file']), default='stdout')
@click.option('--filename', type=click.STRING)
def main(output, filename):
print("output: " + output)
if output == 'file':
if filename is None:
print("filename must be provided!")
else:
print("filename: " + str(filename))
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
如果output
选项是stdout
,则filename
不需要。但是,如果用户选择output
是file
,则filename
必须提供另一个选项。单击是否支持此模式?
在函数的开头,我可以添加如下内容:
if output == 'file' and filename is None:
raise ValueError('When output is "file", a …
Run Code Online (Sandbox Code Playgroud)