[Solved] ‘NoneType’ object has no attribute ‘fileno’

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

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

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>
  File "C:UsersAdministratorAppDataLocalProgramsPythonPython35libsite-packagespandascorebase.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-packagespandasioformatsterminal.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'
Enquirer: frank


Solution #1:

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.

Respondent: frank

Solution #2:

You may wish to try out the following.

df = pd.read_csv('CDNOW_master.txt',usecols = columns,sep = 's+')

instead of

df = pd.read_csv('CDNOW_master.txt',names = columns,sep = 's+')

This solved my problem. Hope it solves yours too.

Respondent: chris dorn

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.