Skip to main content
Tweeted twitter.com/StackCodeReview/status/1283234961911422977
added 10 characters in body; edited tags; edited title
Source Link
Peilonrayz
  • 43.5k
  • 7
  • 76
  • 155

Slow Box&Cox proceess using DataFrame Box and for loop - PythonCox process

I am trying to speed up the followingThe code to obtain Box&Coxobtains Box and Cox transformed data, where the. The original data is a Pandas Dataframe,DataFrame and the process uses this DataFrame.

I am trying to speed up the following code. If you can elaborate in faster way of doing this it would be very helpulhelpful.

import numpy as np
import pandas as pd
from numpy.random import randn
from scipy import stats

np.random.seed(1)
df = pd.DataFrame(np.random.randint(1, 100,size=(100, 4)))

def st_bc(data):
    data_bc = pd.DataFrame()
    for column in list(data):
            data_bc[column], lam = stats.boxcox(data[column])
    return data_bc

st_bc(data = df)
````
import numpy as np
import pandas as pd
from numpy.random import randn
from scipy import stats

np.random.seed(1)
df = pd.DataFrame(np.random.randint(1, 100,size=(100, 4)))

def st_bc(data):
    data_bc = pd.DataFrame()
    for column in list(data):
            data_bc[column], lam = stats.boxcox(data[column])
    return data_bc

st_bc(data = df)

Slow Box&Cox proceess using DataFrame and for loop - Python

I am trying to speed up the following code to obtain Box&Cox transformed data, where the original data is a Pandas Dataframe, and the process uses this DataFrame. If you can elaborate in faster way of doing this it would be very helpul.

import numpy as np
import pandas as pd
from numpy.random import randn
from scipy import stats

np.random.seed(1)
df = pd.DataFrame(np.random.randint(1, 100,size=(100, 4)))

def st_bc(data):
    data_bc = pd.DataFrame()
    for column in list(data):
            data_bc[column], lam = stats.boxcox(data[column])
    return data_bc

st_bc(data = df)
````

Box and Cox process

The code obtains Box and Cox transformed data. The original data is a Pandas DataFrame and the process uses this DataFrame.

I am trying to speed up the following code. If you can elaborate in faster way of doing this it would be very helpful.

import numpy as np
import pandas as pd
from numpy.random import randn
from scipy import stats

np.random.seed(1)
df = pd.DataFrame(np.random.randint(1, 100,size=(100, 4)))

def st_bc(data):
    data_bc = pd.DataFrame()
    for column in list(data):
            data_bc[column], lam = stats.boxcox(data[column])
    return data_bc

st_bc(data = df)
Source Link

Slow Box&Cox proceess using DataFrame and for loop - Python

I am trying to speed up the following code to obtain Box&Cox transformed data, where the original data is a Pandas Dataframe, and the process uses this DataFrame. If you can elaborate in faster way of doing this it would be very helpul.

import numpy as np
import pandas as pd
from numpy.random import randn
from scipy import stats

np.random.seed(1)
df = pd.DataFrame(np.random.randint(1, 100,size=(100, 4)))

def st_bc(data):
    data_bc = pd.DataFrame()
    for column in list(data):
            data_bc[column], lam = stats.boxcox(data[column])
    return data_bc

st_bc(data = df)
````