使用pandas删除整列为空值的列

方法一:

import pandas as pd
# 循环删除空列
import pandas as pd

detail = pd.read_excel('./meal_order_detail.xlsx', sep=',', encoding='gbk')
print(detail)
print(detail.shape)
for i in detail.columns:
    if detail[i].count() == 0:
        detail.drop(labels=i, axis=1, inplace=True)
print(detail)
print(detail.shape)

方法二:

import pandas as pd
# 进行统计非空为0
col = detail.count() == 0  # 返回bool数组
print(col)
for i in range(len(col)):
    if col[i]:
        detail.drop(labels=col.index[i], axis=1, inplace=True)
print(detail.shape)

 

你可能感兴趣的:(pandas,数据分析,pandas)