How to create empty python framework where df.empty results in True
1 answer
The simplest is pd.DataFrame()
:
df = pd.DataFrame()
df.empty
# True
If you want to create a dataframe to specify the number of columns:
df = pd.DataFrame(columns=['A', 'B'])
df.empty
# True
Also, an array of shape (1, 1) is not empty (it has one line), which is why you get empty = False, to create an empty array it must have shape (0, n):
df = pd.DataFrame(pd.np.empty((0, 3)))
df.empty
# True
+6
source to share