3
votes
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:\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'
2
Please provide a copy paste of the entire traceback. It is important to know which line throws the error, because you are quoting an internal pandas error that was triggered by something else. - cs95
there are the traceback above - frank
Where are you running this code? It looks like your stdout has been closed. - cs95
I ran it on Python - frank
I ran it on Python 3.5.1, I have no idea whether stout has been closed,how to check it? - frank

2 Answers

5
votes

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.

0
votes

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.