У меня есть файл csv
с несколькими данными, а ось x
является индексом. Я пытаюсь согласовать данные с pandas
и lmfit
, как показано здесь . Моя цель - иметь отдельную подгонку для отдельных столбцов.
Мой код:
dataset = pandas.read_csv("all2.dat", names=names)
model = LorentzianModel()
params = model.guess(dataset['y'], x=dataset['x'])
result = model.fit(dataset['y'], params, x=dataset['x'])
# box and whisker plots
dataset.plot(kind='line')
plt.show()
, а мой all2.dat
выглядит следующим образом:
3089 , 158 , 228 , 262 , 285 , 87 , 29
3858 , 221 , 282 , 545 , 423 , 116 , 30
4636 , 319 , 401 , 670 , 653 , 164 , 31
5883 , 435 , 525 , 800 , 949 , 209 , 34
7375 , 541 , 674 , 1040 , 1209 , 278 , 40
9172 , 704 , 1231 , 1224 , 1412 , 321 , 47
, что дает ошибку :
Traceback (most recent call last):
File "/home/rudra/.local/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2646, in get_loc
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'y'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ai.py", line 24, in <module>
params = model.guess(dataset['y'], x=dataset['x'])
File "/home/rudra/.local/lib/python3.8/site-packages/pandas/core/frame.py", line 2800, in __getitem__
indexer = self.columns.get_loc(key)
File "/home/rudra/.local/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2648, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'y'
Я попробовал пример в ссылке, с index
как x-axis
, и я получаю ту же ошибку.
Что я здесь не так делаю?