df.head()有时在 pandas ,Python中不起作用 [英] df.head() sometimes doesn't work in Pandas, Python

查看:429
本文介绍了df.head()有时在 pandas ,Python中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python和Pandas库的初学者,我对DataFrame的一些基本功能感到困惑.我有一个如下所示的Pandas DataFrame:

I'm a beginner in Python and the Pandas library, and I'm rather confused by some basic functionality of DataFrame. I've got a pandas DataFrame as below:

>>>df.head()  
              X  Y       unixtime
0  652f5e69fcb3  1  1346689910622
1        400292  1  1346614723542
2  1c9d02e4f14e  1  1346862070161
3        610449  1  1346806384518
4        207664  1  1346723370096

但是,在执行一些功能之后:

However, after I performed some function:

def unixTodate(unix):
  day = dt.datetime.utcfromtimestamp(unix/1000).strftime('%Y-%m-%d')
  return day

df['day'] = df['unixtime'].apply(unixTodate)

我无法再使用df.head()函数:

I could no longer make use of the df.head() function:

>>>df.head()  

<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 190648 to 626582
Data columns:
X              5  non-null values
Y              5  non-null values
unixtime       5  non-null values
day            5  non-null values
dtypes: int64(3), object(5)

我不明白为什么会这样.我在这里做错什么了吗?任何指针都欢迎!谢谢.

I can't see why this is happening. Am I doing something wrong here? Any pointer is welcome! Thanks.

推荐答案

df.head(n)返回包含df的前n行的DataFrame. 现在默认情况下要显示DataFrame熊猫检查终端的宽度,如果该宽度太小而无法显示DataFrame,则将显示摘要视图.在第二种情况下,这是您得到的.

df.head(n) returns a DataFrame holding the first n rows of df. Now to display a DataFrame pandas checks by default the width of the terminal, if this is too small to display the DataFrame a summary view will be shown. Which is what you get in the second case.

您是否可以增加终端的大小,或者通过pd.set_printoptions(max_columns=10)禁用列的自动检测?

Could you increase the size of your terminal, or disable autodetect on the columns by pd.set_printoptions(max_columns=10)?

这篇关于df.head()有时在 pandas ,Python中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆