Print list of empty columns
This commit is contained in:
parent
e551aa88a8
commit
cf58685e23
|
@ -45,6 +45,13 @@ def parse_args():
|
|||
action="store_true",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-e",
|
||||
"--empty",
|
||||
help="List empty columns",
|
||||
action="store_true",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--fields",
|
||||
|
@ -62,6 +69,16 @@ def csv_dump(CSV):
|
|||
print(chunk.to_string())
|
||||
|
||||
|
||||
def csv_empty(CSV):
|
||||
df = pd.read_csv(CSV, low_memory=False, header=0)
|
||||
empty_columns = [col for col in df.columns if df[col].isnull().all()]
|
||||
if empty_columns:
|
||||
print("Empty columns:")
|
||||
print("\n".join(empty_columns))
|
||||
else:
|
||||
print("No empty columns found.")
|
||||
|
||||
|
||||
def csv_fields(CSV):
|
||||
df = pd.read_csv(CSV, low_memory=False, header=0)
|
||||
print("\n".join([col for col in df.columns]))
|
||||
|
@ -74,6 +91,9 @@ def main():
|
|||
if args.dump:
|
||||
csv_dump(CSV)
|
||||
|
||||
if args.empty:
|
||||
csv_empty(CSV)
|
||||
|
||||
if args.fields:
|
||||
csv_fields(CSV)
|
||||
|
||||
|
|
Loading…
Reference in a new issue