【发布时间】:2019-10-10 14:26:57
【问题描述】:
我目前正在处理超过 100 列的数据集,在这 100 列中,前四列为我提供了标签、描述、目标、部门等基本信息。除了其他四列之外,请为我提供数据值。对于那些数据值为空的基本信息,有一些行。我想删除所有数据值为空的所有行。
所以,基本上我做了什么。我做了很长的路。首先,我把整张桌子分成两张桌子。 df1 存储了我的基本信息(标签、描述、目标、部门),df2 存储了我的数据值。现在对于 df2,我使用了 isnull() 方法并找出哪个索引给了我空值。我记下了索引,并连接了两个表。连接后,我基本上根据我记下的索引删除了行。
df1 = pd.read_excel('***.xlsx',skiprows = 5)
df2 = df1.iloc[:,4:]
df2[df2.isnull().all(axis=1)] (*Used this to note down the index of null value rows*)
df1.drop(df1.iloc[:,4:],axis=1,inplace = True) (*Used this to get rid of the data value columns and only leave behind the essential information columns*)
new_df = pd.concat([df1,df2],axis = 1)
new_df.drop(new_df.index[[430,431,432]],inplace = True)
以下方法确实做到了。但是,我感觉它的路很长,所以我想知道是否有更短的方法来解决它? 非常感谢您的帮助
【问题讨论】: