Re: [問題] python pandas time shift已刪文

看板Programming作者 (Neisseria)時間10年前 (2015/07/03 06:53), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #1LbS419a (Programming)
討論串 (同標題文章)
文章代碼(AID): #1LbS419a (Programming)