Python中文
首页
教程
问答
标签
搜索
登录
注册
将Pandas dataframe的行映射到numpy数组中
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>抱歉,我知道有太多关于索引的问题,而且它可能是我的主角,但我有点麻烦。我通常熟悉<code>.loc</code>,<code>.iloc</code>,和{<cd3>}方法和切片。方法<code>.reset_index</code>可能没有(也可能无法)在我们的数据帧上调用,因此索引标签可能没有顺序。dataframe和numpy数组实际上是dataframe的不同长度的子集,但是对于这个示例,我将保持它们的大小相同(一旦有了一个示例,我就可以处理偏移)。在</p> <p>这是一张我想要的照片: <a href="https://i.stack.imgur.com/N66mc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N66mc.jpg" alt="enter image description here"/></a></p> <p>我可以根据一些搜索条件从数据帧中提取行的列。在</p> <pre><code>idxlbls = df.index[df['timestamp'] == dt] stuff = df.loc[idxlbls, 'col3':'col5'] </code></pre> <p>但我如何将其映射到行号(数组索引,而不是标签索引)中用作numpy的数组索引(假设行长度相同)?在</p> ^{pr2}$ <p>我之所以需要它是因为dataframe更大、更完整,并且包含列搜索条件,但是numpy数组是先前在管道中提取和修改过的子集(其中没有相同的搜索条件)。我需要搜索dataframe并从numpy数组中提取等价的数据。基本上,我需要将数据帧中的特定行与numpy数组的相应行相关联。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我会把熊猫指数映射成纽比指数:</p> <pre><code>keys_dict = dict(zip(idxlbls, range(len(idxlbls)))) </code></pre> <p>然后可以使用字典<code>keys_dict</code>通过pandas索引来寻址数组元素:<code>array[keys_dict[some_df_index], :]</code></p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何添加虚拟方法
6 回答
如何添加表示整数的擦边字符串?
10 回答
如何添加要在Bokeh中使用的新font.ttf文件?
6 回答
如何添加要显示的矩阵XY轴编号和XY轴
7 回答
如何添加计数?
1 回答
如何添加计数器函数?
7 回答
如何添加计数器列来计算数据帧中另一列中的特定值?
10 回答
如何添加计数器来跟踪while循环中的月份和年份?
7 回答
如何添加计数并删除countplot的顶部和右侧脊椎?
1 回答
如何添加计时器wx.应用程序更新窗口对象的主循环?
10 回答
如何添加评论到帖子?PostDetailVew,Django 2.1.5
7 回答
如何添加评论拉梅尔亚姆
8 回答
如何添加诸如矩阵Python/Pandas之类的数据帧?
7 回答
如何添加谷歌地点自动完成到Flask?
3 回答
如何添加超时、python discord bot
10 回答
如何添加超过1dp的检查
7 回答
如何添加距离方法
10 回答
如何添加跟随游戏的敌人精灵
1 回答
如何添加路径以便python可以找到程序?
8 回答
如何添加身份验证/安全性以使用happybase访问HBase?
7 回答