I have two csv files:


enter image description here


sub_opt = pd.read_csv('sub_opt.csv')

enter image description here

and what I would like to do is to create a csv file where I have something of the form

compiler, opt

How could I do this? I need to do this to make a submission.

Thank's in advance.

[EDIT] Thank you for the answers. Now I have obtained :

enter image description here

don't understand why I have the columns called unnamed.

My objective is to get a csv file that contains only the columns compiler and opt. How could I do this? Thank's again.

[EDIT 2] I have solved my problem but if I open the csv file manually, so just click on the file, I have the following:

enter image description here

s it contains only 11 lines, but it contains 3000 lines in jupyter. Is it there something wrong?

[EDIT 3] I tried to to the following:

import pandas as pd

test = pd.read_csv('1495927.csv')

and I have:

enter image description here

where 1495927.csv is the csv file I have created and that is in the image where I have 11 elements.

  • $\begingroup$ When you use to_csv try add parameter "index=False" this way when you save it, it will not write the index column in the output file which when you read it will produce the unnamed columns as you saw. Try it first let me know if the problem persists. $\endgroup$ Nov 10, 2019 at 10:46
  • $\begingroup$ Thank's I have created the csv file. Is it normal that when I opened my csv file it contains only 11 lines? $\endgroup$
    – J.D.
    Nov 10, 2019 at 15:14
  • $\begingroup$ That is weird. Can you confirm within the code where you create the combined dataframe that you have the correct dataframe? So far as I observe your update it is heading in the right direction. And my previous comment should solve the issue you face at edit 1 $\endgroup$ Nov 10, 2019 at 15:25
  • $\begingroup$ I have edited my question. In jupyter it seems correct, but when I ioen manually the csv I have only 11 elements in it. I don' understand why. Thank's. $\endgroup$
    – J.D.
    Nov 10, 2019 at 16:27
  • $\begingroup$ Actually by reloading every cell and opening again the csv it is ok now, I have all the rows. Really thank you again. $\endgroup$
    – J.D.
    Nov 10, 2019 at 16:30

3 Answers 3

sub_compiler.merge(sub_opt, how='inner', on='instruction')

This is how to do table join on your table.

Another option if it is already aligned and you just want to concatenate you can do

pd.concat([sub_compiler,sub_opt[['opt']]], axis=1)

This is naive column-wise concatenate.

Finally just proceed with to_csv.


Using pd.DataFrame[['column']] will extract a column as a DataFrame. You can do this on sub_compiler and sub_opt to grab the columns you want. Since they share the same index, you can just align them horizontally with pd.concat.

pd.concat([sub_compiler[['compiler']], sub_opt[['opt']]], axis=1)


An alternative to other (correct) answers: it seems the instructions columns are the same for both, so you could just add the opt columns to the dataframe as a new columns and write that. That way you have all information still (and you said you want something like compiler, opt ;)

sub_compiler["opt"] = sub_opt.opt

Then write to disk as before:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.