using a new function - selection by the called :
cols = ['Name','Sex'] df = (pd.read_csv(filename, header=None, names=cols) [lambda x: np.ones(len(x)).astype(bool) if (x.iloc[0] != cols).all() else np.concatenate([[False], np.ones(len(x)-1).astype(bool)])] )
using . query () method:
df = (pd.read_csv(filename, header=None, names=cols) .query('Name != "Name" and Sex != "Sex"'))
I'm not sure if this is the most elegant way, but this should work too:
df = pd.read_csv(filename, header=None, names=cols) if (df.iloc[0] == cols).all(): df = df[1:].reset_index(drop=True)
source share