Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run code dsc = DiffSynth( data, …… n_optim=100,) raise “TypeError: incompatible index of inserted column with frame index” #28

Open
PG408 opened this issue Oct 27, 2024 · 1 comment

Comments

@PG408
Copy link

PG408 commented Oct 27, 2024

image

@PG408
Copy link
Author

PG408 commented Oct 27, 2024

I seem to have found a solution; it is necessary to modify the difference_data function under the DiffSynth class in main.py. The code is as follows.

        #Compute difference of outcome variable
        temp = modified_dataset.groupby(data.id)[data.outcome_var]
        temp = temp.apply(lambda unit: unit.interpolate(method='linear', limit_direction="both")).diff()
        temp = pd.DataFrame(temp).reset_index()
       
        temp.columns = [data.id, 'index', data.outcome_var]
        temp = temp.set_index('index').sort_index()
        
        modified_dataset[data.outcome_var] = temp[data.outcome_var]
        # modified_dataset[data.outcome_var] = modified_dataset.groupby(data.id)[data.outcome_var].apply(
        #                                     lambda unit: unit.interpolate(method='linear', limit_direction="both")).diff()
        #For covariates
        for col in data.covariates:
            #Fill in missing values using unitwise linear interpolation
            temp2 = modified_dataset.groupby(data.id)[col]
            temp2 = temp2.apply(lambda unit: unit.interpolate(method='linear', limit_direction="both"))
            temp2 = pd.DataFrame(temp2).reset_index()
            temp2.columns = [data.id, 'index', col]
            temp2 = temp2.set_index('index').sort_index()
            modified_dataset[col] = temp2[col]
            # modified_dataset[col] = modified_dataset.groupby(data.id)[col].apply(
            #                         lambda unit: unit.interpolate(method='linear', limit_direction="both"))
            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant