gpt4 book ai didi

python - 更改 pandas 0.13.0 "print dataframe"以像早期版本一样打印数据框

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:37 24 4
gpt4 key购买 nike

在 pandas 的新版本 0.13.0 中,数据帧 df 打印在一长串数字中,使用

df

print df

而不是像以前那样的概述,现在只能使用

df.info()

是否可以更改默认的“df”或“print df”命令以显示:

In [12]: df.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 4319 entries, 2010-02-18 00:00:00 to 2010-03-13 23:15:00
Data columns (total 2 columns):
QInt 4319 non-null values
QHea 4319 non-null values
dtypes: float32(2)

再次代替:

In [11]: df
Out[11]:
QInt QHea
2010-02-18 00:00:00 169.666672 0.000000
2010-02-18 00:15:00 152.000000 -0.000000
2010-02-18 00:15:00 152.000000 -0.000000
2010-02-18 00:30:00 155.000000 -0.000000
2010-02-18 00:30:04 155.063950 -0.000000
2010-02-18 00:30:04 155.063950 -1136.823364
2010-02-18 00:45:00 169.666672 4587.430176
2010-02-18 01:00:00 137.333328 4532.890137
2010-02-18 01:00:00 137.333328 4532.890137
2010-02-18 01:15:00 177.000000 4464.479980
2010-02-18 01:15:00 177.000000 4464.479980
2010-02-18 01:30:00 169.666672 4391.839844
2010-02-18 01:30:00 169.666672 4391.839844
2010-02-18 01:45:00 155.000000 4313.049805
2010-02-18 01:45:00 155.000000 4313.049805
2010-02-18 02:00:00 144.666672 4230.100098
2010-02-18 02:15:00 162.333328 4144.819824
2010-02-18 02:15:00 162.333328 4144.819824
2010-02-18 02:30:00 177.000000 4059.689941
2010-02-18 02:45:00 144.666672 3987.149902
2010-02-18 02:45:00 144.666672 3987.149902
2010-02-18 03:00:00 155.000000 3924.629883
2010-02-18 03:00:00 155.000000 3924.629883
2010-02-18 03:15:00 162.333328 3865.129883
2010-02-18 03:15:00 162.333328 3865.129883
2010-02-18 03:30:00 162.333328 3811.050049
2010-02-18 03:30:00 162.333328 3811.050049
2010-02-18 03:45:00 152.000000 3765.590088
2010-02-18 03:45:00 152.000000 3765.590088
2010-02-18 04:00:00 162.333328 3735.080078
2010-02-18 04:15:00 162.333328 3703.169922
2010-02-18 04:15:00 162.333328 3703.169922
2010-02-18 04:30:00 144.666672 3673.139893
2010-02-18 04:45:00 169.666672 3647.100098
2010-02-18 04:45:00 169.666672 3647.100098
2010-02-18 05:00:00 162.333328 3622.129883
2010-02-18 05:15:00 155.000000 3594.159912
2010-02-18 05:15:00 155.000000 3594.159912
2010-02-18 05:30:00 159.333328 3569.699951
2010-02-18 05:30:00 159.333328 3569.699951
2010-02-18 05:45:00 147.666672 3551.179932
2010-02-18 05:45:00 147.666672 3551.179932
2010-02-18 06:00:00 177.000000 3531.669922
2010-02-18 06:00:00 177.000000 3531.669922
2010-02-18 06:15:00 159.333328 3514.679932
2010-02-18 06:15:00 159.333328 3514.679932
2010-02-18 06:30:00 155.000000 3499.669922
2010-02-18 06:30:00 155.000000 3499.669922
2010-02-18 06:45:00 155.000000 3485.320068
2010-02-18 06:45:00 155.000000 3485.320068
2010-02-18 06:59:54.750000 162.291245 19.999992
2010-02-18 06:59:54.750000 162.291245 0.000000
2010-02-18 07:00:00 162.333328 0.000000
2010-02-18 07:00:00 162.333328 0.000000
2010-02-18 07:15:00 166.666672 0.000000
2010-02-18 07:15:00 166.666672 0.000000
2010-02-18 07:30:00 155.000000 0.000000
2010-02-18 07:30:00 155.000000 0.000000
2010-02-18 07:45:00 155.000000 0.000000
2010-02-18 07:45:00 155.000000 0.000000
... ...

[4319 rows x 2 columns]

最佳答案

设置

pd.options.display.large_repr = 'info'

自 v.0.13 起的默认值为“截断”。

In [93]: df = pd.DataFrame(np.arange(4319*2).reshape(4319,2))

In [94]: pd.options.display.large_repr = 'info'

In [95]: df
Out[95]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 4319 entries, 0 to 4318
Data columns (total 2 columns):
0 4319 non-null int32
1 4319 non-null int32
dtypes: int32(2)

我通过在输出中搜索字符串 'info()' 找到了这个:

In [65]: pd.set_option?

要使其成为交互式 session 的默认行为:

如果你还没有设置它,定义环境变量PYTHONSTARTUP类似于 /home/user/bin/startup.py

然后编辑/创建 /home/user/bin/startup.py 以包含类似的内容

import pandas as pd
pd.options.display.large_repr = 'info'

现在,无论何时启动交互式 Python session ,startup.py 文件都会被执行,您将可以通过 pd 变量访问 pandas,并且 large_repr 默认为 'info'

关于python - 更改 pandas 0.13.0 "print dataframe"以像早期版本一样打印数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21482546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com