小编kgr*_*kgr的帖子

使用python和pandas将OHLC库存数据转换为不同的时间范围

有人可以指出我在与熊猫的 OHLC数据时间框架转换方面的正确方向吗?我正在尝试做的是使用较低时间帧的数据构建具有较高时间帧数据的Dataframe.

例如,给定我有以下一分钟(M1)数据:

                       Open    High     Low   Close  Volume
Date                                                       
1999-01-04 10:22:00  1.1801  1.1819  1.1801  1.1817       4
1999-01-04 10:23:00  1.1817  1.1818  1.1804  1.1814      18
1999-01-04 10:24:00  1.1817  1.1817  1.1802  1.1806      12
1999-01-04 10:25:00  1.1807  1.1815  1.1795  1.1808      26
1999-01-04 10:26:00  1.1803  1.1806  1.1790  1.1806       4
1999-01-04 10:27:00  1.1801  1.1801  1.1779  1.1786      23
1999-01-04 10:28:00  1.1795  1.1801  1.1776  1.1788      28
1999-01-04 10:29:00  1.1793  1.1795  1.1782  1.1789      10
1999-01-04 10:31:00  1.1780  1.1792  1.1776  1.1792      12
1999-01-04 10:32:00  1.1788  1.1792  1.1788  1.1791       4 …
Run Code Online (Sandbox Code Playgroud)

python stock pandas

15
推荐指数
3
解决办法
1万
查看次数

无法获取pyparsing Dict()返回嵌套字典

我正在尝试解析表单的字符串:

'foo(bar:baz;x:y)'
Run Code Online (Sandbox Code Playgroud)

我希望结果以嵌套字典的形式返回,即对于上面的字符串,结果应该如下所示:

{ 'foo' : { 'bar' : 'baz', 'x' : 'y' } }
Run Code Online (Sandbox Code Playgroud)

尽管有许多Dict()和Group()的组合,但我无法让它发挥作用.我的(其中一个版本)语法看起来像这样:

import pyparsing as pp
field_name = pp.Word( pp.alphanums )
field_value = pp.Word( pp.alphanums )
colon = pp.Suppress( pp.Literal( ':' ) )

expr = pp.Dict( 
    pp.Group( 
        field_name + \
        pp.nestedExpr( 
            content = pp.delimitedList( 
                 pp.Group( field_name + colon + field_value ), 
                 delim = ';' 
            ) 
        ) 
    ) 
)
Run Code Online (Sandbox Code Playgroud)

现在,结果如下:

In [62]: str = 'foo(bar:baz;x:y)'

In [63]: expr.parseString( str ).asList()
Out[63]: [['foo', [['bar', 'baz'], ['x', 'y']]]]

In …
Run Code Online (Sandbox Code Playgroud)

python dictionary nested pyparsing

12
推荐指数
1
解决办法
3786
查看次数

在Mac OSX Lion上使用tempfile.mkdtemp()时,Python的os.chdir()和os.getcwd()不匹配

我不知道这是否是一个错误或功能,但是当我使用更改目录os.chdir()与生成的一个tempfile.mkdtemp()然后os.getcwd()报告与目录/private前缀.

以下代码说明了这一点:

In [1]: import os, tempfile

In [2]: d = tempfile.mkdtemp()

In [3]: d
Out[3]: '/var/folders/s4/grpfgn297hjgnfws3tl_gnt80000gn/T/tmpmfNUYz'

In [4]: os.chdir( d )

In [5]: os.getcwd()
Out[5]: '/private/var/folders/s4/grpfgn297hjgnfws3tl_gnt80000gn/T/tmpmfNUYz'
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么会这样吗?

python filesystems macos

5
推荐指数
1
解决办法
1430
查看次数

标签 统计

python ×3

dictionary ×1

filesystems ×1

macos ×1

nested ×1

pandas ×1

pyparsing ×1

stock ×1