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