Reputation: 1
I just use pandas to write a load_data function, then I have bug in my code, I don't know how to deal with that? and my code df.info()
alway has errors AttributeError: 'int' object has no attribute 'info', or the output is
0or
none`
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
Upvotes: 0
Views: 306
Reputation: 653
It's because the load_data
function is returning 0 and not the dataframe that has been loaded. You need to modify your return statement in order for this to work as expected:
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
Upvotes: 1