Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import matplotlib as plt
- from matplotlib import pyplot
- def changeFuel(x):
- if x=="gas":
- return 1
- else:
- return 0
- def changeAspiration(x):
- if x=="turbo":
- return 1
- else:
- return 0
- df=pd.read_csv("automobile_lab4.csv")
- #plt.pyplot.hist(df["horsepower"],bins=3)
- #plt.pyplot.xlabel("horsepower")
- #plt.pyplot.ylabel("count")
- #plt.pyplot.title("horsepower bins")
- #plt.pyplot.show()
- #Dummies
- df["fuel-type-coded"]=df["fuel-type"].apply(lambda x:changeFuel(x))
- df["aspiration-coded"]=df["aspiration"].apply(lambda x:changeAspiration(x))
- print(df[["fuel-type-coded","fuel-type","aspiration-coded"]])
- df.to_csv("DataFrameLimpito.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement