Re: [問題] python pandas time shift已刪文
※ 引述《dreler1 (....)》之銘言:
: I have a set of data with date formate in dd/mm/YY HH:MM
: I try to separate the data into weekday and weekend.
: Therefore, I add a column as weekday to my data called df
: temp = pd.DatetimeIndex(df['date'])
: df['weekday'] = temp.weekday
: It works fine, but it recognize the date as mm/dd/YY HH:MM
: then I tried
: df['DATE'] = datetime.datetime.strptime(df['date'], "%d/%m/%Y %HH:%MM")
: .strftime("%m-%d-%Y %HH:%MM")
: However, an error comes out
: must be string, not Series,
其實錯誤訊息已經告訴你原因了
datetime.strptime 的第一個參數是字串,不是 pandas Series
有關 strptime 的用法可以查 datetime 的文件
如果要對 Series 裡的每個元素都進行某種處理
要用 pandas.Series.apply,然後看你要放什麼函數去處理
BTW,PTT 有 Python 版,以後可以在專版發問看看
: Is there any way to let the program read date correctly?
: Best,
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 69.140.71.14
※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1435877633.A.264.html
推
07/03 08:47, , 1F
07/03 08:47, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章