Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save regispires/33d417cb8d05dd300a82fdf5b5f5144b to your computer and use it in GitHub Desktop.
Save regispires/33d417cb8d05dd300a82fdf5b5f5144b to your computer and use it in GitHub Desktop.
Get types and date columns from a Pandas DataFrame. Same format used in read_csv.
def get_types_dates(df):
cols_names = list(df)
cols_types = df.dtypes
dates = []
types = {}
for i in range(len(cols_names)):
name = cols_names[i]
type_ = cols_types[i].name
if type_[:4] == 'date':
dates.append(name)
else:
types[name] = type_
return types, dates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment