[Solved] How to split a list’s value into two lists [closed]


If you have it as datetimeobject:

datos['day']  = dados['time'].dt.date
datos['time'] = dados['time'].dt.time

If you have it as string object:

datos['day']  = dados['time'].str[:11]
datos['time'] = dados['time'].str[11:]

Or

data[['day', 'time']] = data['time'].str.split(' ').apply(pd.Series)
data[['day', 'time']] = data['time'].str.split(' ', expand=True)

Or using regex

data[['day', 'time']] = data['time'].str.extract('(.*) (.*)')

To convert it to string:

datos['time'] = dados['time'].astype(str)

It is better then converting to normal list [str(x) ...]


To convert it to datetime

datos['time'] = pd.to_datetime(dados['time'])

It may use options – ie. yearfirst=True, dayfirst=True, format="%Y-%m-%d %H:%I:%S"

1

solved How to split a list’s value into two lists [closed]