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

Time:08-03

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

CodePudding user response:

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

  • Related