Home > Mobile >  IndexError & AttributError
IndexError & AttributError

Time:12-21

can someone help me fixing this error? im new in python and im using keggle.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn
dataset = pd.read_csv('../input/datacoba2/Data Penjualan1.csv', sep=",")
x = dataset.iloc[:, :-1:].values
y = dataset.iloc[:, 1].values

in this situation i get error message "IndexError: single positional indexer is out-of-bounds"

dataku = pd.DataFrame(dataset)
plt.scatter(dataku.BiayaProduksi,dataku.NilaiPenjualan)
plt.xlabel("Biaya Produksi")
plt.ylabel("Nilai Penjualan")
plt.title("Grafik Biaya Produksi VS Nilai Penjualan")
plt.show()

and in this situation i get error message "AttributeError: 'DataFrame' object has no attribute 'BiayaProduksi' "

my csv file look like this

BiayaProduksi   NilaiPenjualan
1500        90500
1800        89500
1900        105000
2050        102000
2050        90500
2100        104500
2200        109500
2400        150000
3050        152000
3200        173000
3200        153000
3500        174500
3500        150000
3750        198000
3750        187000
3900        194500
4000        200500
4000        170500
4100        204500
4500        224500

CodePudding user response:

Your data should folow csv format.

Use this to replace your data.

BiayaProduksi,NilaiPenjualan
1500,90500
1800,89500
1900,105000
2050,102000
2050,90500
2100,104500
2200,109500
2400,150000
3050,152000
3200,173000
3200,153000
3500,174500
3500,150000
3750,198000
3750,187000
3900,194500
4000,200500
4000,170500
4100,204500
4500,224500
  • Related