import pandas as pd
carros = ['Jetta Variant','Passat','CrossFox']
carros
pd.Series(carros)
datos = [
{'Nombre': 'Jetta Variant', 'Motor': 'Motor 4.0 Turbo', 'Año': 2003, 'Kilometraje': 44410.0, 'Cero_km': False, 'Valor': 88078.64},
{'Nombre': 'Passat', 'Motor': 'Motor Diesel', 'Año': 1991, 'Kilometraje': 5712.0, 'Cero_km': False, 'Valor': 106161.94},
{'Nombre': 'Crossfox', 'Motor': 'Motor Diesel V8', 'Año': 1990, 'Kilometraje': 37123.0, 'Cero_km': False, 'Valor': 72832.16}
]
dataset = pd.DataFrame(datos)
dataset
dataset[['Nombre','Año','Motor','Kilometraje','Cero_km','Valor']]
datos = {
'Nombre': ['Jetta Variant', 'Passat', 'Crossfox'],
'Motor': ['Motor 4.0 Turbo', 'Motor Diesel', 'Motor Diesel V8'],
'Año': [2003, 1991, 1990],
'Kilometraje': [44410.0, 5712.0, 37123.0],
'Cero_km': [False, False, False],
'Valor': [88078.64, 106161.94, 72832.16]
dataset1 =pd.DataFrame(datos)
dataset1
dataset2 = pd.read_csv('db.csv',sep =';',index_col = 0)
dataset2
dataset2.head()
dataset2['Valor']
type(dataset2['Valor'])
dataset2[['Valor']]
type(dataset2[['Valor']])
dataset2[0:3]
dataset2.loc['Passat']
dataset2.loc[['Passat','DS5']]
dataset2.loc[['Passat','DS5'],['Motor','Valor']]
dataset2.loc[:,['Motor','Valor']]
dataset2.head()
dataset2.iloc[[1]]
dataset2.iloc[1:4]
dataset2.iloc[1:4,[0,5,2]]
dataset2.iloc[[1,42,22],[0,5,2]]
dataset2.iloc[:,[0,5,2]]
dataset2.head()
dataset2.Motor
dataset2.Motor == 'Motor Diesel'
type(dataset2.Motor == 'Motor Diesel')
dataset2[dataset2.Motor == 'Motor Diesel']
dataset2[(dataset2.Motor == 'Motor Diesel') & (dataset2.Cero_km == True)]
dataset2.query('Motor == "Motor Diesel" and Cero_km == True')
dataset2.head()
for item in dataset2:
print(item)
list(dataset2.iterrows())
for index,row in dataset2.iterrows():
if(2020 - row.Año != 0):
dataset2.loc[index,'km_average'] = row.Kilometraje / (2020 - row.Año)
else:
dataset2.loc[index,'km_average'] = 0
dataset2
dataset2.head()
dataset2.info()
dataset2.Kilometraje.isna()
dataset2[dataset2.Kilometraje.isna()]
dataset2.fillna(0)
dataset2
dataset2.fillna(0,inplace = True)
dataset2
dataset2.query('Cero_km == True')
dataset3 = pd.read_csv('db.csv',sep = ';')
dataset3
dataset3.dropna(subset = ['Kilometraje'],inplace = True)
dataset3