Financial Data Science Financial Performance Analysis

From NovaOrdis Knowledge Base
Revision as of 23:14, 20 October 2023 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

Internal

Overview

import math
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ptick

# load the DataFrame
df = pd.read_csv("./finances.csv", parse_dates=["Date"])

# make it a time series DataFrame
df = df.set_index('Date')

# declare the function that converts the dollar amount
def dollar_to_int(s):
    if isinstance(s, str):
        return int(s[1:].replace(',',''))
    elif math.isnan(s):
        return 0
    else:
        return -1

# extract a specific time series and plot it
fidelity_self = df['Fidelity Self'].apply(dollar_to_int)

# graph
fig, ax = plt.subplots()
fig.autofmt_xdate()
ax.set_ylabel("amount")
ax.yaxis.set_major_formatter(mt.FormatStrFormatter('% 1.2f')) 
ax.plot(fidelity_self_managed)
plt.show()