Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'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:\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'
like image 779
frank Avatar asked Feb 23 '26 20:02

frank


1 Answers

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.

like image 131
chris dorn Avatar answered Feb 25 '26 10:02

chris dorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!