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'的结果。

有任何想法吗?非常感谢

这是回溯
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。我假设pandas 想要确定在结果中显示多少,并且正在寻找 sys 输出信息。 In the documentation, it mentions what this is, but not how to reset it.

我这样做了:
sys.__stdout__ = sys.stdout

它解决了问题,但我不知道我是否导致了问题。

关于python - 'NoneType' 对象没有属性 'fileno',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45126368/

10-12 00:31