简体   繁体   English

大家好。 我想在 python 中为附加的数据框编写一个函数。 我不知道我该怎么做

[英]Hi everyone. I want to write a function in python for attached data frame. I can not figure out how can I do it

enter image description here Hi everyone.在此处输入图片描述大家好。 I hope I can explain what I am going to do.我希望我能解释我要做什么。 I want to write a function in python for the attached data frame.我想在 python 中为附加的数据框编写一个函数。 the input will be different T(different names).输入将是不同的 T(不同的名称)。 The p-value for the input T must be less than 0.01 while for the rest of Ts must be more than 0.01, if its true the function must keep that row and then apply this on other rows too.输入 T 的 p 值必须小于 0.01,而其余 T 的 p 值必须大于 0.01,如果为真,则函数必须保留该行,然后也将其应用于其他行。 At the end should return a df which includs col1, col2 , col3.最后应该返回一个包含 col1、col2、col3 的 df。 So all this new rows have a p-value less than 0.01 for the specific T while in other Ts are more than 0.01.因此,对于特定 T,所有这些新行的 p 值都小于 0.01,而其他 T 的 p 值大于 0.01。 I appreciate any advice.我很感激任何建议。


dropped_df = pd.DataFrame()

def check_p_value(df): #pass your dataframe
    dropped_df = df.loc[((df<0.1)).any(1)]

check_p_value(df)

df<0.1 will return a boolean df df<0.1将返回一个布尔值 df

.any(1) returns any true element over the axis 1 (rows) .any(1)返回轴 1 上的任何真元素(行)

df.loc[] then filters the dataframe based on the boolean df df.loc[]然后根据布尔值 df 过滤数据帧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM