File: example_use_pandas.py

package info (click to toggle)
lmfit-py 1.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,332 kB
  • sloc: python: 13,071; makefile: 130; sh: 30
file content (28 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Fit with Data in a pandas DataFrame
===================================

Simple example demonstrating how to read in the data using ``pandas`` and
supply the elements of the ``DataFrame`` to lmfit.

"""
import pandas as pd

from lmfit.models import LorentzianModel

###############################################################################
# read the data into a pandas DataFrame, and use the ``x`` and ``y`` columns:
dframe = pd.read_csv('peak.csv')

model = LorentzianModel()
params = model.guess(dframe['y'], x=dframe['x'])

result = model.fit(dframe['y'], params, x=dframe['x'])

###############################################################################
# and gives the fitting results:
print(result.fit_report())

###############################################################################
# and plot below:
result.plot_fit()