CHARLS_preprocess.py 376 B

1234567891011
  1. import pandas as pd
  2. if __name__ == "__main__":
  3. path = "CHARLS_data_pollutants.csv"
  4. data = pd.read_csv(path, encoding="utf-8")
  5. print(data.info())
  6. data["born_year"] = data.groupby("ID")["born_year"].transform(lambda x : x.fillna(x.mean()))
  7. data["age"] = data["wave"] - data["born_year"]
  8. data.to_csv("CHARLS_data_pollutants_born.csv", encoding="utf-8")