1

I have to read multiple csv on which I have to apply the function describe() to have statistical summaries. So extracting some columns from csv in reading, applying the describe function, then I'd like to save this results into a new csv.

At this moment I'm using this basic commands below, but I do not understand how to save multiple results in one csv sheet.

Thank you for help

# importing pandas module  
import pandas as pd  
    
# read dataframe 1
data1 = pd.read_csv("data1.csv")  

# read dataframe 2
data2 = pd.read_csv("data2.csv")
  
# calling describe method 

desc1 = data1.describe() 
desc2 = data2.describe() 
  
# display 
desc1

desc2
desertnaut
  • 57,590
  • 26
  • 140
  • 166
TforV
  • 135
  • 7
  • 1
    Maybe you can iterate over all the files in a for-loop, call the describe function and save the files? To open/save different files you can use enumerate while looping to keep track of the index and use this index as the 1, 2, 3... in your filenames. – sander Mar 02 '21 at 08:47
  • 1
    Also, if I understood what you want to achieve correctly, you can do it with more than two files easily with two lines of code: `files = ['data1.csv', 'data2.csv']` (you can append the list as long as you desire) and `pd.concat([pd.read_csv(x).describe() for x in files], axis=0, ignore_index=True).to_csv('out.csv')`. And on top of that, with this kind of an approach, it would be a much faster and efficient code. – nizarcan Mar 02 '21 at 09:28
  • thank you @nizarcan I'll try this different way :) – TforV Mar 02 '21 at 09:41
  • 1
    I've realized that there was a slight mistake, `pd.concat`'s axis argument should have been `1`. Sorry for the typo. – nizarcan Mar 02 '21 at 11:06

0 Answers0