-2
I’m making a program based on a file .csv
, but when I run the program the error occurs No numeric types to aggregate
.
File part:
datatime,app version,gender,money
02/09/2019,4,F,$7.43
07/25/2019,1,F,$14.66
01/01/2019,4,M,,$9.99
01/30/2019,5,M,$5.61
04/01/2019,4,F,$13.70
09/26/2019,5,M,$8.84
My code:
import pandas as pd
import matplotlib.pyplot as plt
dados = pd.read_csv('./aplicativo.csv', sep = ',', parse_dates = ['datatime'])
dados['mes'] = pd.DatetimeIndex(dados['datatime'], yearfirst = True).month
def media(m):
return pd.DataFrame(m.groupby('mes')['money'].mean()).reset_index()
ind = media(dados)
plt.title('titulo')
plt.plot(ind['mes'], ind['money'], color = 'b')
plt.xlabel('mes')
plt.ylabel('media de valor pago')
plt.show()
Beautiful answer! Adding: the
errors='coerce'
will put Nan for those values that cannot be converted. Another possibility after removing the$
would bedados['money'] = dados['money'].astype(float, errors='ignore')
. Puttingerrors='ignore'
would cause the value, in the case of a conversion error, to be the original. That is, in the case of a conversion error, it would not aggregate.– Paulo Marques
Show Paulo, thanks for the comment! Big hug!!
– lmonferrari