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问题
如何提高Djang的410误差
5 回答
如何提高doc2vec模型中两个文档(句子)的余弦相似度?
5 回答
如何提高Docker的日志限制?|[输出已剪裁,达到日志限制100KiB/s]
6 回答
如何提高DQN的性能?
6 回答
如何提高EasyOCR的准确性/预测?
5 回答
如何提高Euler#39项目解决方案的效率?
1 回答
如何提高F1成绩进行分类
1 回答
如何提高FaceNet的准确性
6 回答
如何提高fft处理的精度?
6 回答
如何提高Fibonacci实现对大n的精度?
3 回答
如何提高Flask与psycopg2的连接时间
6 回答
如何提高FosterCauer变换的scipy.signal.invres()的数值稳定性?
1 回答
如何提高gae查询的性能?
3 回答
如何提高GANs用于时间序列预测/异常检测的结果
1 回答
如何提高gevent和tornado组合的性能?
5 回答
如何提高googleappengin请求日志的吞吐量
5 回答
如何提高googlevision文本识别的准确性
6 回答
如何提高groupby/apply效率
2 回答
如何提高Gunicorn中的请求率
1 回答
如何提高G中的文件编码转换
2 回答