1

How do I concatenate 2 CSV files using panda such that the resulting CSV file doesn't have row indexes? See example below:

file1.csv

date                    type      price           amount    
2017-09-02 00:00:01     b         0.279111        94000       
2017-09-02 00:00:01     b         0.279           43800          
2017-09-02 00:00:01     b         0.2789          6000     
2017-09-02 00:00:01     b         0.278812        2000         
2017-09-02 00:00:01     b         0.278           7250   

file2.csv

date                    type    price           amount    
2018-03-02 00:00:01     q         0.279111       1400       
2018-05-01 00:00:01     q         0.279          3800          
2017-09-02 00:00:01     q         0.2789         640  

desired_file.csv

date                   type       price           amount    
2017-09-02 00:00:01     b         0.279111        94000       
2017-09-02 00:00:01     b         0.279           43800          
2017-09-02 00:00:01     b         0.2789          6000     
2017-09-02 00:00:01     b         0.278812        2000         
2017-09-02 00:00:01     b         0.278           7250     
2018-03-02 00:00:01     q         0.279111        1400       
2018-05-01 00:00:01     q         0.279           3800          
2017-09-02 00:00:01     q         0.2789          640   

NOT THIS:

     date                   type       price           amount    
1    2017-09-02 00:00:01     b         0.279111        94000       
2    2017-09-02 00:00:01     b         0.279           43800          
3    2017-09-02 00:00:01     b         0.2789          6000     
4    2017-09-02 00:00:01     b         0.278812        2000         
5    2017-09-02 00:00:01     b         0.278           7250     
6    2018-03-02 00:00:01     q         0.279111        1400       
7    2018-05-01 00:00:01     q         0.279           3800          
8    2017-09-02 00:00:01     q         0.2789          640   

My code:

import pandas as pd

a = pd.read_csv("file1.csv")
b = pd.read_csv("file2.csv")

combined = pd.concat([a, b])

combined.to_csv("desired_file.csv")

Thanks :)

1 Answers1

1

Please read the docs

combined.to_csv("desired_file.csv", index=False)
Arunesh Singh
  • 3,489
  • 18
  • 26