Search code examples
pandasdata-analysisfinance

Financial Analysis from CSV File


I need to calculate the following data from a CSV file for a project.

Financial Analysis
  ----------------------------

  Total Months: 86
  Total: $38382578
  Average  Change: $-2315.12
  Greatest Increase in Profits: Feb-2012 ($1926159)
  Greatest Decrease in Profits: Sep-2013 ($-2196167)

I've already imported pandas and numpy. I made pandas read the csv and print the data.

This is the csv file: CSV File

This is what I have so far in Jupyter Lab: code


Solution

  • You can use agg() and pass the required functions as a List[str].

    df.agg(["count", "max", "mean","min"])
    

    From what is visible in your screenshot, I get the following output.

    Output:

               Date  Profit/Losses
    count        25           25.0
    max    Sep-2011      1033096.0
    mean        NaN       432313.2
    min    Apr-2010      -755566.0