【发布时间】:2018-02-15 05:31:10
【问题描述】:
我希望能够像这样创建一个交叉表/表/数据框(无论名称如何):
____________________
Performance "value" (This value must come from a X vector, which has a formula to go to dataset, calculate and return this value)
____________________
LTFU "value" (This value must come from a y vector, which has a formula to go to dataset, calculate and return this value)
____________________
请注意,Performance 和 LTFU 值是从应用到 python 中的 .csv 数据集的函数生成的。 .csv 数据集中不存在性能和 LTFU,两者都应该创建只是为了让我对性能进行总结。
我现在得到的如下:
import pandas as pd
performance=pd.read_csv("https://www.dropbox.com/s/08kuxi50d0xqnfc/demo.csv?dl=1")
x=performance["idade"].sum()
y=performance["idade"].mean()
l = "Performance"
k = "LTFU"
def test(y):
return pd.DataFrame({'a':y, 'b':x})
test([l,k])
a b
0 Performance x vector value here (it shows 1300, it is correct)
1 LTFU y vector value here (it shows 1300, it is wrong, it should show 14.130434782608695 instead, according to the instruction of y vector)
您可以将上述代码复制并粘贴到您的 python IDE 并进行测试,然后将您的解决方案返回给我。 请根据我的需要向我展示一个包含表格结果的示例。
【问题讨论】:
-
我的文字在这里被扭曲了。我正在发布屏幕截图
-
你想做什么?您是否尝试以相同的格式保存为 CSV / txt?或者您是否想总结此数据框以供重用?
-
@Deena,我正在尝试用新变量来总结这个数据框。我想要的是从数据集中的另一个变量中计算这两个值。我想获得另一个计算生成的新值。请注意,csv 数据集中不存在 Perfomance 和 LTFU。它们是刚刚创建的新变量,用于总结我想要的。
-
我很困惑
test([l,k])返回DataFrame。那么需要将其写入文件吗?或者需要从csv-Performance 1300 ____________________ LTFU 60创建另一个DataFrame,将其添加到test([l,k])并回写? -
是的,耶斯瑞尔。我需要根据我上面的函数创建另一个表(或任何名称的数据框),其中包含正确的性能值 1300,并且还必须包含 LTFU 值(不能为 1300,因为生成此值的函数与性能不同) .收到了吗?
标签: python function pandas crosstab