简体   繁体   English

如何在pydatatable中输入数据框列?

[英]How to type cast a dataframe column in pydatatable?

I'm trying to explore datatypes of a frame in pydatatable.我正在尝试探索 pydatatable 中框架的数据类型。

Here I have a dataframe:这里我有一个数据框:

ventas_duda_dt = dt.Frame(
    {"cust_id":[893232.34],"sales":['$123,4532.93'],"profit_perc":['10%']})

and its types:及其类型:

ventas_duda_dt.stypes

and the datatypes of each of these fields as:以及每个字段的数据类型为:

(stype.float64, stype.str32, stype.str32)

Now I would like to cast three of these columns to int, float, float from float, str, str , here.现在我想将这些列中的三列转换为int, float, float from float, str, str ,在这里。 How it can be achieved by removing these special symbols ($,,,%) in field values?如何通过删除字段值中的这些特殊符号($,,,%)来实现?

I was going though the documentation, but I couldn't find a reference over there respect to this topic.我正在阅读文档,但在那里找不到关于此主题的参考。

In datatable the easiest way to change a column's type is to assign the new type to the column:datatable更改列的类型,最简单的方法是将新类型分配给列:

ventas_duda_dt["cust_id"] = int
ventas_duda_dt["sales"] = float
ventas_duda_dt["profit_perc"] = float

However, in your example the situation is more complicated because the string values are not directly convertible.但是,在您的示例中,情况更加复杂,因为字符串值不能直接转换。 You'd need special converters that know about percent signs, comma-separated numbers, currency symbols, etc. Such functionality doesn't exist in datatable yet, but it may be possible to add it in the future, provided that you can specify what exactly such converters should do.您需要知道百分号、逗号分隔数字、货币符号等的特殊转换器。数据表中尚不存在此类功能,但将来可能会添加它,前提是您可以指定什么正是这样的转换器应该做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM