Python Pandas:返回满足特定条件的列的列标题

Python Pandas:返回满足特定条件的列的列标题,python,pandas,Python,Pandas,我有一些数据,希望获得样本量较小(例如总行数

我有一些数据,希望获得样本量较小(例如总行数<90%)的列的列标题。如何获取它们的列表,可能以列表或数据帧的形式返回

在下面的示例中,我希望将
FieldC
作为输出

使用
列车测向头()

我认为你可以做到:

columnsToBeReturn=[]
max=df.shape[0] #getting the shape of the entire dataframe so the biggest number of rows
for col in df.columns: 
   if len(df[col])<max*0.9:
       columsToBeReturn.append(col)
return columnsToBeReturn
columnsToBeReturn=[]
max=df.shape[0]#获取整个数据帧的形状,使行数最大
对于df.列中的列:
如果len(df[col])我认为您可以:

columnsToBeReturn=[]
max=df.shape[0] #getting the shape of the entire dataframe so the biggest number of rows
for col in df.columns: 
   if len(df[col])<max*0.9:
       columsToBeReturn.append(col)
return columnsToBeReturn
columnsToBeReturn=[]
max=df.shape[0]#获取整个数据帧的形状,使行数最大
对于df.列中的列:
if len(df[col])
“object”的索引也可以转换为一系列文本字符串


“object”的索引也可以转换为一系列文本字符串。

看起来您想要的是行标题,而不是列标题
train_df[train_df.count()@DYZ谢谢你的评论。我也试过了,但是我得到了错误
IndexingError:Unalignable boolean Series key提供了
对不起。必须是
train_df.count()[train_df.count()看起来你想要的是行标题,而不是列标题?
train_df[train_df.count()@DYZ谢谢你的评论。我也试过了,但是我得到了错误
IndexingError:Unalignable boolean Series key提供了
对不起。必须是
train_df.count()[train_df.count()
columnsToBeReturn=[]
max=df.shape[0] #getting the shape of the entire dataframe so the biggest number of rows
for col in df.columns: 
   if len(df[col])<max*0.9:
       columsToBeReturn.append(col)
return columnsToBeReturn
>>> _=pandas.DataFrame({'horse':[3,None],'cow':[1,2],'sheep':[None,None]})
>>> _
   cow  horse sheep
0    1    3.0  None
1    2    NaN  None
>>> criterion2=_.columns[_.count()>2]
>>> criterion1=_.columns[_.count()>1]
>>> criterion0=_.columns[_.count()>0]
>>> criterion2
Index([], dtype='object')
>>> criterion1
Index(['cow'], dtype='object')
>>> criterion0
Index(['cow', 'horse'], dtype='object')
>>> _[criterion2]
Empty DataFrame
Columns: []
Index: [0, 1]
>>> _[criterion1]
   cow
0    1
1    2
>>> _[criterion0]
   cow  horse
0    1    3.0
1    2    NaN
>>> pandas.__version__
'0.22.0'