2021年3月29日星期一

Manipulate string to drop columns on pandas

I'm trying to manipulate a list (type: string) to use that list to drop some columns from a dataframe. Dataframe

The list is from a dataframe that I created a condition to return columns whose sums of all values ​​are zero:

Selecting the columns with sum = 0

condicao_CO8 = (ex8_centro_oeste.sum(axis = 0) == 0)  condicao_CO8 = condicao_CO8[condicao_CO8 == True]  condicao_CO8.to_csv('D:\Programas\CO_8.csv')  

Importing the dataframe and turning it into a list:

CO8 = pd.read_csv(r'D:\Programas\CO_8.csv',                   delimiter=','                   )  CO8.rename(columns={'Unnamed: 0': 'Nulos'}, inplace = True)  CO8.rename(columns={'0': 'Info'}, inplace = True)  CO8.drop(columns = ['Info'], inplace = True)  CO8.columns            

Images from the list: List

Some itens from the list:

0                                          ABI - LETRAS  1                                 ADMINISTRAÇÃO PÚBLICA  2                                             AGRONOMIA  3                                             ALIMENTOS  4                                          ARQUIVOLOGIA  5                                  AUTOMAÇÃO INDUSTRIAL  6                                           BIOMEDICINA  7                                         BIOTECNOLOGIA  8                                   CIÊNCIAS - BIOLOGIA  9                                    CIÊNCIAS - QUÍMICA  10                                    CIÊNCIAS AGRÁRIAS  11                                  CIÊNCIAS BIOLÓGICAS  12                    CIÊNCIAS BIOLÓGICAS E CONSERVAÇÃO  13                               CIÊNCIAS DA COMPUTAÇÃO  14                                  CIÊNCIAS ECONÔMICAS   

My goal is to transform the list so that I can drop the columns from that.

Transforming this list into this: "ABI - LETRAS", "ADMINISTRAÇÃO PÚBLICA", "AGRONOMIA", "ALIMENTOS", "ARQUIVOLOGIA", "AUTOMAÇÃO INDUSTRIAL"...

for this I made the following code (unsuccessful)

list_CO8 = ('\",\" '.join(CO8['Nulos'].apply(str.upper).tolist()))

Please, can anyone help me?

I'm trying to get:

list = "ABI - LETRAS", "ADMINISTRAÇÃO PÚBLICA", "AGRONOMIA", "ALIMENTOS", "ARQUIVOLOGIA", "AUTOMAÇÃO INDUSTRIAL"...  

To make: ex8_centro_oeste.drop(columns=[list])

Dataset link: Link for Drive (8kb)

https://stackoverflow.com/questions/66864005/manipulate-string-to-drop-columns-on-pandas March 30, 2021 at 10:29AM

没有评论:

发表评论