python中的标准日期和时间框架

python中的标准日期和时间框架,python,twitter,standards,Python,Twitter,Standards,我正在使用以下代码将str('1495596971')转换为'%Y-%m-%d%H:%m:%S',但无法对整个列执行此操作。你能帮我一下吗 ho['tweet'] = ho['tweet'].astype(str) c=ho['tweet'] stddate=c.split('.')[0].split('0')[1] t=print( datetime.datetime.fromtimestamp( int(stddate) ).strftime('%Y-%m-

我正在使用以下代码将str('1495596971')转换为'%Y-%m-%d%H:%m:%S',但无法对整个列执行此操作。你能帮我一下吗

ho['tweet'] = ho['tweet'].astype(str)
c=ho['tweet']
stddate=c.split('.')[0].split('0')[1]


t=print(
    datetime.datetime.fromtimestamp(
       int(stddate)
    ).strftime('%Y-%m-%d %H:%M:%S')
)
它正在显示此错误:-“Series”对象没有属性“split”

输入:-

              tweet
0     1495596971.6034188::automotive auto ebc greens...
1     1495596972.330948::new free stock photo of cit...
2     1495596972.775966::ebay: 1974 volkswagen beetl...
3     1495596975.6460807::cars fly off a hidden spee...
4     1495596978.12868::rt @jiikae: guys i think mar...

我只需要'1495596971'、'1495596972'等从列中删除此数据,并希望将其转换为标准日期和时间格式

您可以使用Series对象上的apply选项对serie as列中的每条记录进行操作

ho['tweet'] = ho['tweet'].astype(str)
c=ho['tweet']
stddate=c.apply(lambda x:x.split('.')[0])

熊猫系列没有方法拆分,您可以做的是获取每一项,然后使用
'.
拆分,然后获取str
('1495596971')
,将其转换并格式化:

import pandas as pd
import datetime
c =  pd.Series(['1495596971.6034188::automotive auto ebc greens','1495596972.330948::new free stock photo of cit','1495596972.775966::ebay: 1974 volkswagen beetl'])
stddate_list = [c[i].split('.')[0] for i in range(len(c))]
print(stddate_list)
t = [datetime.datetime.fromtimestamp(int(stddate)).strftime('%Y-%m-%d %H:%M:%S') for stddate in stddate_list]
print(t)
stddate\u列表的输出
t

['1495596971', '1495596972', '1495596972']
['2017-05-24 11:36:11', '2017-05-24 11:36:12', '2017-05-24 11:36:12']

AttributeError:'str'对象没有属性'plit'我遇到此错误。打字错误…其拆分事实上,我想在拆分后将'1495596971'转换为标准日期和时间格式。嘿,你知道如何使用c[0]获取所有行的stddate而不是特定行。我看不到你对此问题的答案