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'
答案 0 :(得分:5)
我也看到了这一点。
>>> type(sys.__stdout__)
<class 'NoneType'>
当我使用空闲时调用dunder stdout时,我得到NoneType。我假设大熊猫想要确定在结果中显示多少并且正在寻找sys输出信息。 In the documentation, it mentions what this is, but not how to reset it.
我这样做了:
sys.__stdout__ = sys.stdout
它解决了问题,但我不知道我是否会引起问题。
答案 1 :(得分:0)
您可能希望尝试以下内容。
df = pd.read_csv('CDNOW_master.txt',usecols = columns,sep = '\s+')
而不是
df = pd.read_csv('CDNOW_master.txt',names = columns,sep = '\s+')
这解决了我的问题。希望它也能解决你的问题。