Search code examples
pythongaussianlmfit

How to fit a Gaussian into my data (csv) file using Python


I have collated the data and have it in CSV.format. I wish to fit a Gaussian into my data using Python. Can someone help me with the starting steps? I have gone through the lmfit. documentation from Python. I'm not very sure how to go about it.


Solution

  • Fitting a Gaussian is as simple as calculating the mean and the standard deviation of your data:

    import numpy as np
    
    data = <load data here>
    
    mu = np.mean(data)
    sigma = np.std(data, ddof=1)
    

    Here, mu and sigma are the two parameters of the Gaussian.