Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib as plt
  4. from matplotlib import pyplot
  5. def changeFuel(x):
  6. if x=="gas":
  7. return 1
  8. else:
  9. return 0
  10.  
  11. def changeAspiration(x):
  12. if x=="turbo":
  13. return 1
  14. else:
  15. return 0
  16.  
  17. df=pd.read_csv("automobile_lab4.csv")
  18. #plt.pyplot.hist(df["horsepower"],bins=3)
  19. #plt.pyplot.xlabel("horsepower")
  20. #plt.pyplot.ylabel("count")
  21. #plt.pyplot.title("horsepower bins")
  22. #plt.pyplot.show()
  23. #Dummies
  24.  
  25. df["fuel-type-coded"]=df["fuel-type"].apply(lambda x:changeFuel(x))
  26. df["aspiration-coded"]=df["aspiration"].apply(lambda x:changeAspiration(x))
  27.  
  28. print(df[["fuel-type-coded","fuel-type","aspiration-coded"]])
  29. df.to_csv("DataFrameLimpito.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement