我的問題被洗掉了,無法撤消。
uj5u.com熱心網友回復:
這是你想做的嗎?
def pandasFilter(filePath):
df1 = pd.read_csv(filePath) #creating a dataframe
nd = df1.select_dtypes("number") #only selecting the numeric columns
v_i = pd.DataFrame(nd.nunique()).reset_index() #show amount of unique values
col=v_i[v_i[0]==v_i[0].max()]["index"] #target column label with the highest amount of unique values
if len(col)==1: #if there is only one column with the highest amount of unique values
col=col.squeeze()
colmean=df[col].mean() #get column mean
results=df[df[col]<colmean] #queried results
else: #if there are multiple columns with the highest amount of unique values
results=pd.DataFrame() #return empty dataframe
return results
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534883.html
標籤:Python熊猫格式文件
