r/PythonLearning • • 11h ago

Discussion Well.... i think this code is totally fine right?

from sklearn.impute import SimpleImputer 
import pandas as pd
from matminer.datasets import load_dataset
electronic_df = load_dataset("boltztrap_mp")
temperature_df = load_dataset("ucsb_thermoelectrics")
gap_df = load_dataset("expt_gap_kingsbury")


#changing neme:composition in temp_df to formular
df_temp = temperature_df.rename(columns={"composition": "formula"})
print(df_temp.columns.tolist())


#Trying to combine three of them
a = pd.merge(electronic_df,df_temp,on="formula",how="left")
com_df = pd.merge(a,gap_df,on="formula",how="left")
# Seperating the num data and text data
num_cols = com_df.select_dtypes(include="number").columns
# text_cols = com_df.select_dtypes(exclude="number").columns


num_imputer = SimpleImputer(strategy="median")
# text_imputer = SimpleImputer(strategy="most_frequent") : no need
com_df[num_cols] = num_imputer.fit_transform(com_df[num_cols])
# com_df[text_cols] = text_imputer.fit_transform(com_df[text_cols])
0 Upvotes

2 comments sorted by

1

u/Sea-Ad7805 5h ago

Maybe you want to tell us a bit more about what the intend of the code is? Otherwise most people won't take the time to read it.

1

u/Sweet_Computer_7116 4h ago

No dude this code is bloody amazing. Never seen anything like it. You should sell the code