Guest User

Untitled

a guest
Jan 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. df = pd.read_csv(r"C:UsersEddieDownloadspandasDeformation.txt",
  2. error_bad_lines=False)
  3. df.dropna(axis=1, how="all", inplace=True)
  4.  
  5. suffixes = ["_A", "_B"]
  6.  
  7. for suffix in suffixes:
  8. # Välj ut alla DIG*_*-kolumner och spara i en lista
  9. dig_cols = [col for col in df.columns if (col.replace("
  10. ","").startswith("DI") and col.endswith(suffix))]
  11.  
  12. # Säkerställ att alla DIG*_*-kolumner är decimaltal
  13. for col in dig_cols:
  14. df[col] = df[col].astype(float)
  15. df[col].replace(0, np.nan, inplace=True)
  16. df[col].fillna(method="ffill", inplace=True)
  17.  
  18. path = r"C:UsersEddieDownloadspandas"
  19. df.to_csv(os.path.join(path, "Deformation_new.txt"))
Add Comment
Please, Sign In to add comment