The code below worked with the previous csv that I used, both csv's have the same amount of columns, and the columns have the same name.
Data for the csv that worked here
Data for csv that didnt here
What does this error mean? Why am I getting this error?
from pandas import read_csv
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot
series = read_csv('carringtonairtemp.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
groups = series.groupby(Grouper(freq='A'))
years = DataFrame()
for name, group in groups:
years[name.year] = group.values
years = years.T
pyplot.matshow(years, interpolation=None, aspect='auto')
pyplot.show()
Error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-7173fcbe8c08> in <module>
6 # display(group.head())
7 # print(group.values[:10])
----> 8 years[name.year] = group.values
e:\Anaconda3\lib\site-packages\pandas\core\frame.py in __setitem__(self, key, value)
3038 else:
3039 # set column
-> 3040 self._set_item(key, value)
3041
3042 def _setitem_slice(self, key: slice, value):
e:\Anaconda3\lib\site-packages\pandas\core\frame.py in _set_item(self, key, value)
3114 """
3115 self._ensure_valid_index(value)
-> 3116 value = self._sanitize_column(key, value)
3117 NDFrame._set_item(self, key, value)
3118
e:\Anaconda3\lib\site-packages\pandas\core\frame.py in _sanitize_column(self, key, value, broadcast)
3759
3760 # turn me into an ndarray
-> 3761 value = sanitize_index(value, self.index)
3762 if not isinstance(value, (np.ndarray, Index)):
3763 if isinstance(value, list) and len(value) > 0:
e:\Anaconda3\lib\site-packages\pandas\core\internals\construction.py in sanitize_index(data, index)
745 """
746 if len(data) != len(index):
--> 747 raise ValueError(
748 "Length of values "
749 f"({len(data)}) "
ValueError: Length of values (365) does not match length of index (252)
