Python Vaex data type conversion

风格不统一 提交于 2021-01-24 11:36:07

问题


I'm utilizing the Vaex library in Python for a project; I'm still very new to Vaex so I apologize if this is elementary. I'm having an issue with a data type conversion. One of my columns 'Paid_at' has a datatype of str, and it should be a DateTime. df_paid.info

What I've done so far is dropped na from my df as well as (tried to) used pandas' to_datetime() to convert the column but it isn't working. This has worked in a pd data frame, but I am doing something wrong as I am receiving the following error

df_paid['Paid_at'] = pd.to_datetime(df['Paid_at'], errors='coerce')

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in ----> 1 df_paid['Paid_at'] = pd.to_datetime(df['Paid_at'], errors='coerce')

F:\Anaconda3\lib\site-packages\vaex\dataframe.py in setitem(self, name, value) 4431 self.add_column(name, value)
4432 else: -> 4433 self.add_virtual_column(name, value) 4434 else: 4435 raise TypeError('setitem only takes strings as arguments, not {}'.format(type(name)))

F:\Anaconda3\lib\site-packages\vaex\dataframe.py in add_virtual_column(self, name, expression, unique) 3249
'# we rewrite all existing expressions (including the passed down expression argument) 3250 self._rename(name, renamed) -> 3251 expression = _ensure_string_from_expression(expression) 3252 3253 name = vaex.utils.find_valid_name(name, used=[] if not unique else self.get_column_names())

F:\Anaconda3\lib\site-packages\vaex\utils.py in _ensure_string_from_expression(expression) 764 return expression.expression 765 else: --> 766 raise ValueError('%r is not of string or Expression type, but %r' % (expression, type(expression))) 767 768

ValueError: NaT is not of string or Expression type, but <class 'pandas._libs.tslibs.nattype.NaTType'>

I'm a bit lost as to how I can get the Paid_at column to be a DateTime which I can aggregate from.


回答1:


df2['pdate']=df2.date.astype('datetime64[ns]')

was solved here: https://github.com/vaexio/vaex/pull/440



来源:https://stackoverflow.com/questions/62648122/python-vaex-data-type-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!