In [1]:
import pandas as pd
In [2]:
df = pd.DataFrame(pd.np.arange(12).reshape(3, 4), columns=['a', 'b', 'c', 'd'], index=['x', 'y', 'z'])
print(df)
In [3]:
print((df > 3) & (df % 2 == 0))
In [4]:
# print((df > 3) and (df % 2 == 0))
# ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
In [5]:
# print(df > 3 & df % 2 == 0)
# ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
In [6]:
print(df & 7)
In [7]:
print(df | 1)
In [8]:
# print(df << 1)
# TypeError: unsupported operand type(s) for <<: 'DataFrame' and 'int'
In [9]:
# print(df << df)
# TypeError: unsupported operand type(s) for <<: 'DataFrame' and 'DataFrame'
In [10]:
print(df > 3)
In [11]:
print((df > 3).all())
In [12]:
print((df > 3).all(axis=1))
In [13]:
print((df > 3).all(axis=None))
In [14]:
print(df.empty)
In [15]:
df_empty = pd.DataFrame()
print(df_empty.empty)
In [16]:
print(df.size)
In [17]:
print(df_empty.size)