首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pd.info()在AttributeError中:'int‘对象没有属性'info’

pd.info()在AttributeError中:'int‘对象没有属性'info’
EN

Stack Overflow用户
提问于 2022-11-03 19:12:44
回答 1查看 20关注 0票数 0

我只是用熊猫编写了一个load_data函数,然后我的代码中出现了错误,我不知道该如何处理?而且我的代码df.info()总是有错误,AttributeError: 'int' object has no attribute 'info', or the output is 0or

代码语言:javascript
复制
import numpy as np
import pandas as pd
import csv
from io import StringIO

def load_data():
    buffer = StringIO()
    #df.info(buf = buffer)
    #buffer.getvalue()
    #with open('work.csv', ';') as f:
    pd.read_csv('work.csv',';', encoding="utf-8")
    return 0

df = load_data()
print(df.info())
代码语言:javascript
复制
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 740 entries, 0 to 739
Data columns (total 21 columns):
 #   Column                           Non-Null Count  Dtype  
---  ------                           --------------  -----  
 0   ID                               740 non-null    int64  
 1   Reason for absence               740 non-null    int64  
 2   Month of absence                 740 non-null    int64  
 3   Day of the week                  740 non-null    int64  
 4   Seasons                          740 non-null    int64  
 5   Transportation expense           740 non-null    int64  
 6   Distance from Residence to Work  740 non-null    int64  
 7   Service time                     740 non-null    int64  
 8   Age                              740 non-null    int64  
 9   Work load Average/day            740 non-null    float64
 10  Hit target                       740 non-null    int64 
EN

回答 1

Stack Overflow用户

发布于 2022-11-03 19:20:37

这是因为load_data函数返回的是0,而不是已经加载的数据。你需要修改你的返回语句,这样才能像预期的那样工作:

代码语言:javascript
复制
def load_data():
    buffer = StringIO()
    #df.info(buf = buffer)
    #buffer.getvalue()
    #with open('work.csv', ';') as f:
    df = pd.read_csv('work.csv',';', encoding="utf-8")
    return df 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74308436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档