[英]How to manipulate a Python object to get information on time
我有這種類型的數據
0 days 11:07:00.000000000
我想只保留0 days 11:07
。 格式為dtype('O') - (Python) objects
。 我能怎么做?
如果是字符串,您可以使用rpartition
def convert(data):
return str(s.rpartition(':')[0])
例子:
>>> s = '0 days 11:07:00.000000000'
>>> s = str(s.rpartition(':')[0])
>>> s
0 days 11:07
如果你是這個意思
df = pd.DataFrame( {'c': ["0 days 11:07:00.000000000"]})
df['c'].dtype
Output
dtype('O')
然后你可以使用這個
df['c'].astype(str).apply(lambda x : ":".join(x.split(":")[0:2]))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.