小编Jon*_*Jon的帖子

仅从 Pandas 数据框中解开一列的一部分

我有以下示例数据框:

df = pd.DataFrame(data = {'RecordID' : [1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5], 'DisplayLabel' : ['Source','Test','Value 1','Value 2','Value3','Source','Test','Value 1','Value 2','Source','Test','Value 1','Value 2','Source','Test','Value 1','Value 2','Source','Test','Value 1','Value 2'],
'Value' : ['Web','Logic','S','I','Complete','Person','Voice','>20','P','Mail','OCR','A','I','Dictation','Understandable','S','I','Web','Logic','R','S']})
Run Code Online (Sandbox Code Playgroud)

创建此数据框:

+-------+----------+---------------+----------------+
| Index | RecordID | Display Label |     Value      |
+-------+----------+---------------+----------------+
|     0 |        1 | Source        | Web            |
|     1 |        1 | Test          | Logic          |
|     2 |        1 | Value 1       | S              |
|     3 |        1 | Value 2       | I              |
|     4 |        1 | …
Run Code Online (Sandbox Code Playgroud)

python pivot dataframe melt pandas

10
推荐指数
2
解决办法
341
查看次数

使用带有多个ndb.get_multi_async的yield

我正在尝试从appengine数据存储区提高当前查询的效率.目前,我正在使用同步方法:

class Hospital(ndb.Model):
      name = ndb.StringProperty()
      buildings= ndb.KeyProperty(kind=Building,repeated=True)
class Building(ndb.Model):
      name = ndb.StringProperty()
      rooms= ndb.KeyProperty(kind=Room,repeated=True)
class Room(ndb.Model):
      name = ndb.StringProperty()
      beds = ndb.KeyProperty(kind=Bed,repeated=True)
class Bed(ndb.Model):
      name = ndb.StringProperty()
      .....
Run Code Online (Sandbox Code Playgroud)

目前我经历了愚蠢的事情:

currhosp = ndb.Key(urlsafe=valid_hosp_key).get()
nbuilds = ndb.get_multi(currhosp.buildings)
for b in nbuilds:
   rms = ndb.get_multi(b.rooms)
   for r in rms:
      bds = ndb.get_multi(r.beds)
      for b in bds:
          do something with b object
Run Code Online (Sandbox Code Playgroud)

我想使用get_multi_async将其转换为更快的查询

我的困难在于如何做到这一点?有任何想法吗?

最好的乔恩

python google-app-engine asynchronous app-engine-ndb

8
推荐指数
1
解决办法
1974
查看次数

获得Pandas Pivot表中另一列的百分比

我试图在pandas中获得类似的excel功能,主要是类型行为的百分比.使用以下数据:

{'A': ['a', 'b', 'b', 'a', 'a', 'a', 'b', 'b', 'b', 'a', 'a', 'a', 'b'], 
 'C': ['e', 'e', 'e', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'e', 'e'], 
 'B': ['c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', 'd', 'c', 'c', 'd'], 
 'D': ['g', 'g', 'h', 'h', 'g', 'g', 'h', 'h', 'g', 'g', 'h', 'h', 'g'], 
 'V1': [84.0, 440.0, 423.0, 63.0, 990.0, 192.0, 169.0, 387.0, 934.0, 208.0, 834.0, 923.0, 230.0], 
 'V2': [120.0, 942.0, 153.0, 284.0, 517.0, 695.0, 37.0, 30.0, …
Run Code Online (Sandbox Code Playgroud)

python pivot-table pandas

2
推荐指数
1
解决办法
3262
查看次数

Python方法定义中的"**params"语法是什么?

所以我正在尝试谷歌应用程序引擎搜索库的新python代码,我遇到了一个奇怪的语法.这是:

cls_createDocument(**params)
Run Code Online (Sandbox Code Playgroud)

params是一本字典.

这涉及的功能是:

    @classmethod
  def _createDocument(
      cls, pid=None, category=None, name=None, description=None,
      category_name=None, price=None, **params)
Run Code Online (Sandbox Code Playgroud)

我的问题是,**params表示什么以及它对该对象有什么作用?

谢谢!乔恩

python syntax

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