'NoneType'对象没有属性'fileno' [英] 'NoneType' object has no attribute 'fileno'

查看:99
本文介绍了'NoneType'对象没有属性'fileno'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime

plt.style.use('ggplot')
columns = ['user_id','order_dt','order_products','order_amount']
df = pd.read_csv('CDNOW_master.txt',names = columns,sep = '\s+')
df['order_date'] = pd.to_datetime(df.order_dt,format='%Y%m%d')
df['month'] = df.order_date.values.astype('datetime64[M]')
f = df.groupby('user_id')['month'].min().value_counts()
print(f)

以上是我的代码,我的目的是获取第一个月内购买的用户的value_counts,但仅得到"NoneType"对象的结果,而没有属性"fileno".

Above is my code,my purpose is to get the value_counts of the users purchased in their first month, but only got the result of 'NoneType' object has no attribute 'fileno'.

有什么想法吗?非常感谢

any ideas? much appreciate

这是回溯

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\practice\CDNOW.py", line 19, in <module>
    print(f)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\base.py", line 51, in __str__
    return self.__unicode__()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\series.py", line 982, in __unicode__
    width, height = get_terminal_size()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\io\formats\terminal.py", line 33, in get_terminal_size
    return shutil.get_terminal_size()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 1071, in get_terminal_size
    size = os.get_terminal_size(sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'

推荐答案

我也看到了这一点.

>>> type(sys.__stdout__)
<class 'NoneType'>

我在使用空闲时调用dunder stdout时得到NoneType.我假设熊猫想确定要在结果中显示多少,并且正在寻找sys输出信息. 在文档中,它提到了这是什么,但没有提到如何重置它.

I get NoneType when calling dunder stdout while I am using idle. I assume that pandas wants to determine how much to display in the results and is looking for the sys output information. In the documentation, it mentions what this is, but not how to reset it.

我这样做了:

sys.__stdout__ = sys.stdout

它解决了问题,但是我不知道我是否造成了问题.

and it fixed the problem, but I have not idea if I caused problems down the line.

这篇关于'NoneType'对象没有属性'fileno'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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