-2

how to use try: and raise exception: for empty dataframe.

import pandas as pd

name_dict = {'name': [], 'score':[]}
df = pd.DataFrame(name_dict)
print(df)
AK007
  • 51
  • 5
  • 1
    https://stackoverflow.com/questions/19828822/how-to-check-whether-a-pandas-dataframe-is-empty - `if df.empty: raise Exception("whatever")`. – luk2302 Jul 05 '22 at 07:41

1 Answers1

0

Use pandas.DataFrame.empty attribute

import pandas as pd
df = pd.DataFrame()
if df.empty:
    raise Exception("DataFrame must not be empty")
Daweo
  • 31,313
  • 3
  • 12
  • 25