我只是用熊猫编写了一个load_data函数,然后我的代码中出现了错误,我不知道该如何处理?而且我的代码df.info()总是有错误,AttributeError: 'int' object has no attribute 'info', or the output is 0or
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())<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 发布于 2022-11-03 19:20:37
这是因为load_data函数返回的是0,而不是已经加载的数据。你需要修改你的返回语句,这样才能像预期的那样工作:
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 https://stackoverflow.com/questions/74308436
复制相似问题