Data tidying and cleaning - problem 2
Здравейте, при преимменуването на колонките от задача 1 от лаб-а ми излиза следната грешка:
ValueError: Length mismatch: Expected axis has 1 elements, new values have 9 elements
Ето и кода, който пиша:
import pandas as pd
import nose.tools
from pandas import DataFrame
import nose.tools
from pandas import DataFrame
mpg_data = None
mpg_data = pd.read_csv("http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data")
mpg_data
mpg_data = pd.read_csv("http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data")
mpg_data
mpg_data.head(3)
mpg_data_dataframe = pd.DataFrame(mpg_data)
print(mpg_data_dataframe.columns)
mpg_data_dataframe.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model_year', 'origin', 'car_name']
mpg_data_dataframe.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model_year', 'origin', 'car_name']
Грешката след последния ред е следната:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-17-3b58cbb62092> in <module>()
----> 1 mpg_data_dataframe.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model_year', 'origin', 'car_name']
ValueError Traceback (most recent call last)
<ipython-input-17-3b58cbb62092> in <module>()
----> 1 mpg_data_dataframe.columns = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model_year', 'origin', 'car_name']
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __setattr__(self, name, value)
4383 try:
4384 object.__getattribute__(self, name)
-> 4385 return object.__setattr__(self, name, value)
4386 except AttributeError:
4387 pass
4383 try:
4384 object.__getattribute__(self, name)
-> 4385 return object.__setattr__(self, name, value)
4386 except AttributeError:
4387 pass
pandas\_libs\properties.pyx in pandas._libs.properties.AxisProperty.__set__()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in _set_axis(self, axis, labels)
643
644 def _set_axis(self, axis, labels):
--> 645 self._data.set_axis(axis, labels)
646 self._clear_item_cache()
647
643
644 def _set_axis(self, axis, labels):
--> 645 self._data.set_axis(axis, labels)
646 self._clear_item_cache()
647
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\internals.py in set_axis(self, axis, new_labels)
3321 raise ValueError(
3322 'Length mismatch: Expected axis has {old} elements, new '
-> 3323 'values have {new} elements'.format(old=old_len, new=new_len))
3324
3325 self.axes[axis] = new_labels
3321 raise ValueError(
3322 'Length mismatch: Expected axis has {old} elements, new '
-> 3323 'values have {new} elements'.format(old=old_len, new=new_len))
3324
3325 self.axes[axis] = new_labels
ValueError: Length mismatch: Expected axis has 1 elements, new values have 9 elements
Задачата е да преименувам колонките. Дейтасет-а , който ползваммм е този .
Някой може ли да ми каже къде бъркам?
Благодаря! сработи :)