访问dataframe列时出现非类型错误

时间:2017-08-22 12:56:40

标签: pandas dataframe series nonetype

我有一个来自数据库的数据框:

    sql = "SELECT * FROM Data ORDER BY TimeOfEvent"
    DF = pd.io.sql.read_sql(sql, self.cnxn)

DF:

   EventKeyID   TimeOfEvent  EventConfigId EventCode  EventSymbolId  \
0              20  1.816608e+09              1     12563             50   
1               2  1.816608e+09              5    Log on              1   
2              31  1.816608e+09              1     12563             50   
etc..

我尝试使用不同的方法将列EventCode作为一个系列访问:

print(DF.EventCode)

print(DF['EventCode'])

但收到错误:

AttributeError: 'NoneType' object has no attribute 'fileno'

我可以使用.tolist()将其作为列表,但需要将列作为一个系列,因此我可以使用.str.startswith来查找以“Log”开头的值。

0 个答案:

没有答案