1

I have two files from where I need to fetch information for data analysis. I am using Python Pandas for this. Any help on how to do this will be appreciated.

I already know how merge 2 files using Python - I am looking forward to achieve this job in PANDAS particularly.

Once 2 files merged then I need to get some analytical data out of it. Both these file do have same structure of data in CSV format.

Pralhad Narsinh Sonar
  • 1,406
  • 1
  • 14
  • 23

2 Answers2

6

I would suggest to read the csv files into dataframes and concatenate them this way

frames = [pd.read_csv('f1.csv'), pd.read_csv('f2.csv')]
result = concat(frames,ignore_index=True)
farhawa
  • 10,120
  • 16
  • 49
  • 91
4
df1 = pd.read_csv(file1)
df2 = pd.read_csv(file2)

df_combined = pd.concat([df1,df2])

df_combined.to_csv(combined_file_name)
cammil
  • 9,499
  • 15
  • 55
  • 89
  • Isn't the problem of this that df1 and df2 will remain in memory, even if one would utilize only df_combined from that point onwards. Thus one basically stores the same data twice? Unless pd has some functionality that it doesn't copy, but only references df1, df2? In that case farhawa's solution is more efficient? https://stackoverflow.com/q/18295630/4959635 – mavavilj Jan 20 '20 at 09:34