我有以下格式的csv
Used CPU Used Memory Hard CPU Hard Memory
1 4Gi 50 24Gi
0 0 0 0
2 4Gi 4 8Gi
2 4Gi 4 8Gi
0 0 100m 128Mi
51550m 39528Mi 56 47Gi
它们是字符串值。在这个表中,515500是指需要转换成核心的毫核心。39528Mi是Mebibyte,我需要将其转换为gibibyte(或大约)。我想知道如何读取每个值列,以及是否找到m
(如5150m),将其转换为岩芯。然后将列的所有值转换为整数,这样我就可以将它们全部相加。在
我想用熊猫,但我对它很陌生。我知道我可以尝试df["col_name"].astype("int")
来转换为整数,但我也需要解释millicore值来转换它们。在
任何帮助都是非常感谢的。在
预期输出:所有值都必须是浮点值。我从下面的对话中得知
^{pr2}$
在pandas中定制函数非常容易。 也许你可以试试这些:
我没有找到任何简单的方法,这里有一个肮脏的方法 基本上,列包含不同的字符串(Gi和Mi),需要单独计算。所以,你可以这样做。另外,我在这里没有计算硬CPU列,但是想法是相同的,基本上你可以为它使用相同的模式(比如Used CPU column)。在
现在,对于第二列,也有Gi值,所以可以像这样重复相同的内容
^{pr2}$因为列中的每个项都需要不同的数学转换,如果存在这样的字符串。我能想到的简单可行的解决办法就是这样。很抱歉
你可以这样做。在
更新:
输入:
^{pr2}$输出:
他们在浮动64。现在您可以使用
df['Hard Memory'] + df['Used Memory']
相关问题 更多 >
编程相关推荐