Mikal Fischer
Mikal Fischer

Reputation: 21

Wait for Python to finish before next loop

I've tried a few different methods, even just raw wait(240) but it appears that this sometimes doesnt even given enough time.

However I can not get these 2 lines to return before it loops into the next for.

    f.summary()
    f.get_best(method='sumsquare_error')
import numpy as np
import pandas as pd
import seaborn as sns
from fitter import Fitter#, get_common_distributions, get_distributions
from fitter import get_common_distributions

from fitter import get_distributions

from IPython.display import clear_output
import warnings
import pandas as pd
from pandas.core.common import SettingWithCopyWarning
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)

import time
import subprocess

dataset = pd.read_csv("econ.csv")

for col in dataset.columns:
    try:
        print(col)
        
        spac = dataset[col].values
        f = Fitter(spac, distributions=get_distributions())
        f.fit()
        f.summary()
        f.get_best(method='sumsquare_error')
        print("")
        #subprocess.call
        
        #result = col.result
        #time.sleep(180)
        
    except:
        pass

Upvotes: 0

Views: 183

Answers (1)

Mikal Fischer
Mikal Fischer

Reputation: 21

Yes @crunker99, you are correct, the notebook does appear to be jumping on because of the f.get_best(...) not being the last line.

As such I set up an empty dataframe and captured the outputs as such.

df = pd.DataFrame({'Name': pd.Series([], dtype='str'),
                   'Output': pd.Series([], dtype='str')})

df.loc[n]=[col]+[f.get_best(method='sumsquare_error')]

Cheers! A bit silly on my side! haha

Upvotes: 1

Related Questions