Python Vaex 数据类型转换 [英] Python Vaex data type conversion

查看:227
本文介绍了Python Vaex 数据类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中使用 Python 中的 Vaex 库;我对 Vaex 还是很陌生,所以如果这是初级的,我深表歉意.我遇到了数据类型转换的问题.我的一列Paid_at"的数据类型为 str,它应该是 DateTime.df_paid.info

到目前为止我所做的是从我的 df 中删除 na 以及(试图)使用熊猫的 to_datetime() 来转换列,但它不起作用.这在 pd 数据框中有效,但我在收到以下错误时做错了

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

<块引用>

--------------------------------------------------------------------------- ValueError 回溯(最近一次调用最后)在---->1 df_paid['Paid_at'] = pd.to_datetime(df['Paid_at'], errors='coerce')

F:\Anaconda3\lib\site-packages\vaex\dataframe.py in setitem(self,名称,值)4431 self.add_column(名称,值)
4432 其他:->4433 self.add_virtual_column(name, value) 4434 else: 4435 raise TypeError('setitem 只需要字符串作为参数,而不是 {}'.format(type(name)))

F:\Anaconda3\lib\site-packages\vaex\dataframe.py 中add_virtual_column(self, name, expression, unique) 3249
'# 我们重写所有现有的表达式(包括传递下来的表达式参数) 3250 self._rename(name,重命名)->3251 表达式 = _ensure_string_from_expression(expression) 3252 3253 name = vaex.utils.find_valid_name(name, used=[] 如果不是唯一的,否则self.get_column_names())

F:\Anaconda3\lib\site-packages\vaex\utils.py 中_ensure_string_from_expression(表达式)第764回765 其他:-->766 raise ValueError('%r 不是字符串或表达式类型,而是 %r' % (表达式,类型(表达式)))767768

ValueError: NaT 不是字符串或表达式类型,而是 <class'pandas._libs.tslibs.nattype.NaTType'>

我对如何让 Paid_at 列成为我可以从中聚合的 DateTime 有点迷茫.

解决方案

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

在这里解决:https://github.com/vaexio/vaex/pull/440

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.

解决方案

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

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

这篇关于Python Vaex 数据类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆