Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - 'NoneType' object has no attribute '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)

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

here are the traceback

Traceback (most recent call last):
  File "C:UsersAdministratorDesktoppracticeCDNOW.py", line 19, in <module>
    print(f)
  File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libsite-packagespandascorease.py", line 51, in __str__
    return self.__unicode__()
  File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libsite-packagespandascoreseries.py", line 982, in __unicode__
    width, height = get_terminal_size()
  File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libsite-packagespandasioformatserminal.py", line 33, in get_terminal_size
    return shutil.get_terminal_size()
  File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libshutil.py", line 1071, in get_terminal_size
    size = os.get_terminal_size(sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am seeing this as well.

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

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.

I did this:

sys.__stdout__ = sys.stdout

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...