Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

412
Visualizações
Extracting specific columns from pandas.dataframe

I'm trying to use python to read my csv file extract specific columns to a pandas.dataframe and show that dataframe. However, I don't see the data frame, I receive Series([], dtype: object) as an output. Below is the code that I'm working with: My document consists of: product sub_product issue sub_issue consumer_complaint_narrative
company_public_response company state zipcode tags
consumer_consent_provided submitted_via date_sent_to_company
company_response_to_consumer timely_response consumer_disputed?
complaint_id

I want to extract : sub_product issue sub_issue consumer_complaint_narrative

import pandas as pd

df=pd.read_csv("C:\\....\\consumer_complaints.csv")
df=df.stack(level=0)
df2 = df.filter(regex='[B-F]')
df[df2]
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

import pandas as pd

input_file = "C:\\....\\consumer_complaints.csv"
dataset = pd.read_csv(input_file)
df = pd.DataFrame(dataset)
cols = [1,2,3,4]
df = df[df.columns[cols]]

Here specify your column numbers which you want to select. In dataframe, column start from index = 0

cols = []

You can select column by name wise also. Just use following line

df = df[["Column Name","Column Name2"]]
over 4 years ago · Santiago Trujillo Relatório

0

A simple way to achieve this would be as follows:

df = pd.read_csv("C:\\....\\consumer_complaints.csv")
df2 = df.loc[:,'B':'F']

Hope that helps.

over 4 years ago · Santiago Trujillo Relatório

0

This worked for me, using slicing:

df=pd.read_csv

df1=df[n1:n2]

Where $n1<n2# are both columns in the range, e.g: if you want columns 3-5, use

df1=df[3:5]

For the first column, use

df1=df[0]

Though not sure how to select a discontinuous range of columns.

We can also use i.loc. Given data in dataset2:

dataset2.iloc[:3,[1,2]]

Will spit out the top 3 rows of columns 2-3 (Remember numbering starts at 0)

enter image description here

Then dataset2.iloc[:3,[1,2]] spits out

enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda