0
I have a 'data.csv' file, with the data below:
turma,nome,code,motivo,atividade,trofeus,data
9º Ano Fundamental A,Maria Joana,9X4YK,Realizar atividade Astromaker,Lição A,3,21/02/2020 11:44:11
9º Ano Fundamental A,Maria Joana,9X4YK,Realizar atividade Astromaker,Lição B,3,28/02/2020 11:46:49
9º Ano Fundamental A,Maria Joana,9X4YK,Realizar atividade Astromaker,Lição B,3,06/03/2020 11:31:43
9º Ano Fundamental A,José Antonio,9XV62,Realizar atividade Astromaker,Lição B,3,14/02/2020 12:28:55
I created a class to read the csv file:
import pandas as pd
class DataFrame(object):
def __init__(self, name_file):
self.name_file = name_file
self.df = self.read_file()
return self.df
def read_file(self):
try:
self.df = pd.read_csv(self.name_file)
except IndexError:
print('Erro: nome de arquivo incorreto')
return self.df
Below I include in the same class, functions to make filters and groupings, for example:
def soma_trofeus_aluno(self):
self.df = self.df.groupby(['turma', 'nome', 'code'])['trofeus'].sum().reset_index()
def filtro_aluno(self, df, aluno):
self.aluno = ''
self.df = df[df['nome'].str.contains(self.aluno)]
return self.df
But none of the def I tried worked. I’m trying to call them that:
def main():
dados = DataFrame('dados.csv')
dados.filtro_aluno(dados, 'Maria')
dados.exibir_df()
if __name__ == '__main__':
main()
How can I pass my 'def' correctly and call them?
My dear, too much value, I am not give area, but I am studying some programming languages and marking to use in the area of education. I do not know why this does not reach in our area, because it helps too much for the better all day to day of a teacher and a school. I ended up using your second option, only the
def
, because then it worked to play inside a "system" inside the python even being able to select data and filters with thedef
. Thus, it is summing up in days work minutes. SHOWWWW– Rony Deikson Santana
@Ronydeiksonsantana Well, I would say for now do not use classes and focus only on algorithms and functions even. After mastering the basics, then you can go for more complicated things (classes/object orientation is a more complicated topic and even experienced people in the area hit head on this)
– hkotsubo
agree. I will focus on algorithms and
def
first. What is already speeding up my day to day with students. I can already extract from the site an automatic csv and post summary of the lessons all using python modules.– Rony Deikson Santana
I’m glad that here at Stackoverflow I get good explanations and help to evolve.
– Rony Deikson Santana