【发布时间】:2019-09-27 10:54:33
【问题描述】:
我有下面的数据帧。
d = {'id': ['x1', 'x2','x3','x4','x5','x6','x7'],'t1': [3,11,4,4,10,16,8],'t2':[20,14,4,15,22,11,4],
't3':[14,2,12,18,16,16,11]}
df = pd.DataFrame(data=d)
我想在 t1 上添加包含排序的列,然后如果两行的 t1 相等,那么我们可以查看 t2 并做同样的事情。 我的专栏将包含。
df['calculated'] =[7,2,6,5,3,1,4]
我的预期数据框是:
d = {'id': ['x1', 'x2','x3','x4','x5','x6','x7'],'t1': [3,11,4,4,10,16,8],'t2':[20,14,4,15,22,11,4],
't3':[14,2,12,18,16,16,11],'calculated':[7,2,6,5,3,1,4]}
df = pd.DataFrame(data=d)
【问题讨论】:
-
如何获取计算列? .是你期望的输出吗?
-
只是想要的输出
-
您应该显示您的预期数据框......我们需要了解您的需求
-
@anky_91 我更新了我原来的帖子。请看一下
-
@Miss 当然,谢谢,你能解释一下你是如何得到第一行的 7 的吗?
标签: python-3.x pandas sorting dataframe