第64个数据帧列的行为与第64个数据帧列不同(wrt descripe and to \u csv函数)

2024-04-26 22:03:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试导出熊猫(v0.19.2)数据帧-从读取excel和一些操作-到一个CSV文件。你知道吗

虽然有些列被识别为float64,但是toïcsv函数中的descripe方法和float格式都不起作用。。。(不过,它们在处理随机生成的数据时确实非常有效)。你知道吗

基本上,这条线

df["my_column"].describe()

返回以下内容:

count     5.0
unique    5.0
top       7.0
freq      1.0
Name: my_column, dtype: float64

而我希望它能像这样返回

count    6.000000
mean     0.276880
std      1.032943
min     -1.542513
25%     -0.103334
50%      0.797131
75%      0.896404
max      1.083524
Name: my_column, dtype: float64

导出到CSV文件时相同:

df["my_column"].to_csv("test.csv", sep=';', decimal=',', float_format="%.2f")

创建以下文件:

0;220
1;154
2;7
3;140.800003051758
4;48.4000015258789

我希望:

0;220,00
1;154,00
2;7,00
3;140,80
4;48,40

我是不是漏了什么?你知道吗


Tags: 文件csvto数据函数namedfmy