python的head函数输不出数据_df.head()有时在熊猫,Python中不起作用

1586010002-jmsa.png

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)

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

>>>df.head()

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) 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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值