0

I was unable to use the .weekday() method because data['Date'] is formatted as a string. However, when I tried to use a look to change data type to date it produced an error, saying it was a foat?

dates = []

for date in data['Date']:
    dtobj = datetime.strptime(date,'%Y-%m-%d')
    dates.append(dtobj)

TypeError: strptime() argument 1 must be str, not float
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    try: `data['Date'] = pd.to_datetime(data['Date'])`. you might not need to specify the format string. – mechanical_meat Feb 18 '22 at 18:34
  • That worked. Much thanks. I guess I was trying to use a datetime method in a pandas dataframe? I wouldn't have thought that would cause a problem, but I'm relatively novice. – Chicory Feb 18 '22 at 18:49
  • 1
    generally you'd want to avoid looping over a DataFrame and try to use vectorized operations or just operate over entire columns -- to the extent possible -- instead of cell by cell. – mechanical_meat Feb 18 '22 at 19:31

0 Answers0