Re: [問題] python pandas time shift

作者: Neisseria (Neisseria)   2015-07-03 06:53:51
※ 引述《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,

Links booklink

Contact Us: admin [ a t ] ucptt.com