1

嗨,我刚刚开始使用 Python 中的 Vaex。我有一个列名混乱的数据集。我正在尝试用“_”替换空格。

在熊猫中,我可以 df.column = df.columns.str.replace(' ', '_')

但在 Vaex

df_column = df.column_names.str.replace('\s', '_', regex=True)

我收到以下错误


----> 1 df_new = df.column_names.str.replace('\s', '_', regex=True) 中的 AttributeError Traceback (最近一次调用最后一次) AttributeError: 'list' object has no attribute 'str'

有谁知道我可能做错了什么?

谢谢迈克

4

1 回答 1

5

在 Vaex 中,这些列实际上是“表达式”。表达式允许您在执行常规数据帧操作时在幕后构建某种计算图。但是,这要求列名尽可能“干净”。

因此不允许使用像“2”或“2.5”这样的列名,因为表达式系统可以将它们解释为数字而不是列名。还有像'first-name'这样的列名,表达式系统可以解释为df['first'] - df['name']。

为了避免这种情况,vaex 将巧妙地重命名列,以便它们可以在表达式系统中使用。这实际上是极其复杂的。顺便说一句,您始终可以通过 df.get_column_names(alias=True) 访问原始名称。

如果要重命名列,则应使用df.rename(name, new_name)

我希望这有帮助!

于 2020-06-10T08:45:35.433 回答