Output error if there is value under NaN header in Excel file

Question:

I have inputed Excel table, that look like this:

head_1 head_2 head_3
val_1  val_2  val_3
val_4  val_5  val_6  val_7

I need to output error, because under the NaN header there is value(val_7), but i have no idea how to implement it

Asked By: nex_lex

||

Answers:

try:

assert sum(['unnamed' in col.lower() for col in df.columns])==0, 
    f"Values present in {sum(['unnamed' in col.lower() for col in df_1.columns])} unnamed column(s)"

result:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [23], in <cell line: 1>()
----> 1 assert sum(['unnamed' in col.lower() for col in df.columns])==0, 
      2     f"Values present in {sum(['unnamed' in col.lower() for col in df.columns])} unnamed column(s)"

AssertionError: Values present in 1 unnamed column(s)

it works if you don’t have the word "unnamed" in any of your columns names

Answered By: 99_m4n
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.