Created
July 25, 2020 21:21
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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