I have inputed Excel table, that look like this:
JavaScript
x
4
1
head_1 head_2 head_3
2
val_1 val_2 val_3
3
val_4 val_5 val_6 val_7
4
I need to output error, because under the NaN header there is value(val_7), but i have no idea how to implement it
Advertisement
Answer
try:
JavaScript
1
3
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_1.columns])} unnamed column(s)"
3
result:
JavaScript
1
8
1
---------------------------------------------------------------------------
2
AssertionError Traceback (most recent call last)
3
Input In [23], in <cell line: 1>()
4
----> 1 assert sum(['unnamed' in col.lower() for col in df.columns])==0,
5
2 f"Values present in {sum(['unnamed' in col.lower() for col in df.columns])} unnamed column(s)"
6
7
AssertionError: Values present in 1 unnamed column(s)
8
it works if you don’t have the word “unnamed” in any of your columns names