Python中文
首页
教程
问答
标签
搜索
登录
注册
如何复制数据帧以匹配其他数据帧的长度?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>假设以下数据帧:</p> <p>df1型:</p> <pre><code>a 10. 20. 30. 40. 50. 60. 70. 80. 90. 100. 110. 120. </code></pre> <p>df2型:</p> <pre><code>b 1. 2. </code></pre> <p>df3公司:</p> <pre><code>b 1. 2. 3. </code></pre> <p>知道了<code>len(df1.values) % len(df2.values) == 0</code>,我想用<code>df1</code>的每个元素除以<code>df2</code>的每个元素,在重复了<code>df2</code>尽可能多的次数以适应<code>df1</code>1的长度之后,在本例中就是这样</p> <p>结果(df1,df2):</p> <pre><code>a 10. 10. 30. 20. 50. 30. 70. 40. 90. 50. 110. 60. </code></pre> <p>结果(df1,df3):</p> <pre><code>a 10. 10. 10. 40. 25. 20. 70. 40. 30. 100. 55. 40. </code></pre> <p>实现这一点最干净的方法是什么,最好不经过numpy?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我会的</p> <pre><code>n=len(df1)//len(df2) df1.a/np.tile(df2.b,n+1)[:len(df1)] Out[871]: 0 10.0 1 10.0 2 30.0 3 20.0 4 50.0 5 30.0 6 70.0 7 40.0 8 90.0 9 50.0 10 110.0 11 60.0 Name: a, dtype: float64 </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
9 回答
将Pandas数据帧转换为scipy稀疏矩阵
8 回答
将Pandas数据帧转换为Spark Datafram时出现问题
6 回答
将pandas数据帧转换为spark DataFram时出错
10 回答
将Pandas数据帧转换为spark datafram时收到错误
1 回答
将Pandas数据帧转换为Spark数据帧
1 回答
将Pandas数据帧转换为Tensorflow数据
7 回答
将Pandas数据帧转换为tkinter obj
7 回答
将pandas数据帧转换为XML
1 回答
将Pandas数据帧转换为值sql语句
1 回答
将pandas数据帧转换为元组
5 回答
将pandas数据帧转换为元组列表
6 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
4 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
8 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
1 回答
将pandas数据帧转换为内存中类似文件的对象?
4 回答
将Pandas数据帧转换为内存功能(&F)
8 回答
将pandas数据帧转换为列表列表
4 回答
将pandas数据帧转换为列表列表以输入到RNN
10 回答
将Pandas数据帧转换为单行DataFram
10 回答