If I have a dataframe of random values:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,10, size=[5, 5]))
and I choose any column and run the following code:
for x in df[0]:
print(x in df[0])
I would expect the output to be:
True
True
True
True
True
but it isn't. It prints an assortment of "True" and "False". It seems to be printing "True" for items in range(5) and False otherwise. I tried changing my dataframe to:
df = pd.DataFrame(np.random.randint(0,10, size=[6, 6]))
and the same code prints True for elements in range(6). If I change the condition to:
for x in df[0]:
print(x in list(df[0]))
It prints all True as expected (regardless of the size of the dataframe). Can anyone explain why this is?