0

I had put a file into pandas dataframe, i have 2 header rows here. which goes by column-1,response ; column-2, response etc.

Column -1   Column-2    Which of the following Marvel films have you seen?  Please select all that apply.   
Response    Response    Avengers              Iron Man

Yes           No        Avengers              Iron Man
Yes           No        Avengers              Iron Man
Yes           Yes       Avengers              Iron Man
Yes           Yes       Avengers              Iron Man
Yes           No        Avengers              Iron Man

This is what i used; to merge both the header rows as 1 column. But, this give me a multi header index .

    data = pd.read_csv("D:\\Users\\703228597\\Documents\\python\\StarWars.csv" ,header = [0,1],encoding= 'unicode_escape') 

If i want to perform EDA's, what is the Column_name i use ? since, it is a multi-index header

data1[data1.Column_name < 0] 
kilmonger
  • 41
  • 7
  • Don't post jpeg pictures but sample code, so that your problem is reproducible. It's also necessary to articulate, how the final solution should look like. In your case read_csv() most likely ends up with a multiindex dataframe? – Peter Apr 18 '20 at 12:08
  • i have modified the question – kilmonger Apr 19 '20 at 19:36
  • [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Peter Apr 19 '20 at 19:54

1 Answers1

0
df = pd.read_csv('yourfile.csv', header = 1)

This looks like it should work. Not too sure what you're trying to achieve. I'm guessing you want to index the id column.

df = df.set_index('id_column')

however, if you're looking for two headers, your question is answered here: Giving a column multiple indexes/headers

HarriS
  • 605
  • 1
  • 6
  • 19