Python中文
首页
教程
问答
标签
搜索
登录
注册
拆分和合并pandas datafram
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试拆分和合并Pandas数据帧。在</p> <p>原始数据帧的列排列如下:</p> <pre><code>dataTime Record1Field1 ... Record1FieldN Record2Field1 ... Record1FieldN time1 << record 1 data >> << record 2 data >> </code></pre> <p>我想把<code>Record2</code>字段拆分成一个单独的数据帧<code>tempdf</code>,按dataTime索引。<code>tempdf</code>因此看起来像这样:</p> ^{pr2}$ <p>填充<code>tempdf</code>后,从原始数据框中删除Record2列。我遇到的第一个困难是创建包含记录2数据的<code>tempdf</code>。在</p> <p>然后,我想重命名<code>tempdf</code>中的列,以便它们与原始数据框中的<code>Record1</code>列对齐。(这部分我知道怎么做)</p> <p>最后,我想将<code>tempdf</code>合并回原始数据帧中。在</p> <p>最终结果应该如下所示:</p> <pre><code>dataTime Record1Field1 ... Record1FieldN time1 <<record 1 data>> time1 <<record 2 data>> </code></pre> <p>到目前为止,我还没有找到一个好的方法。感谢任何帮助!谢谢。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>如果知道要选择的列,则使用</p> <pre><code> tempdf = df[['a','b']] </code></pre> <p>否则要选择最后2列,请使用</p> ^{pr2}$
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
为什么在使用strptime时会出现未进行转换的数据错误?
5 回答
为什么在使用strptim时会出现这个datetime日期错误
4 回答
为什么在使用StyleFrame时索引列的标题不显示sf.至excel()?
3 回答
为什么在使用sum()函数时会发生“int”对象不可调用的错误?
3 回答
为什么在使用sympy.dsolve时会得到“'list'对象没有属性'func'”?
3 回答
为什么在使用tabla时会得到一个空的数据帧?
3 回答
为什么在使用tensorboard时需要add_graph()的第二个参数?
10 回答
为什么在使用TensorFlow Lite转换YOLOv4时,推断时间/大小没有改进?有什么可能的改进吗?
10 回答
为什么在使用Tensorflow加载训练批时会出现内存泄漏?
7 回答
为什么在使用tensorflow时会收到警告/错误(使用函数API,但未实现错误)
9 回答
为什么在使用tetpyclient发出POST请求时出现403错误?
3 回答
为什么在使用TextBlob时会出现HTTP错误?
8 回答
为什么在使用TFIDF时出现错误“IndexError:list index out of range”pyspark.ml.feature?
5 回答
为什么在使用timedelta格式化之后,我在python中的日期是错误的?
7 回答
为什么在使用timeit或exec函数时,函数中的变量不会在提供的全局命名空间中搜索?
1 回答
为什么在使用tkinter时不能使用复选框?
6 回答
为什么在使用todoistpythonapi时会返回这个奇怪的ID?
6 回答
为什么在使用TQM时,在调整图像大小时,处理时间会有很大的差异?
1 回答
为什么在使用Tweepy下载用户时间线时收到错误消息
8 回答
为什么在使用twitter帐户登录Django应用程序时重定向127.0.0.1:8000?
7 回答