From a daily report, I use:
pd.read_csv(filepath, sep = '\t')
to open a dataframe looking like the below (in simplified format):
finalDf2 = pd.DataFrame(dict(
Portfolio = pd.Series(['Book1', 'Book1', 'Book2', 'Book3', 'Book1','Book1']),
Strike = pd.Series(['108','109.10', '111', '114', '108.3', '115.0']),
Notional = pd.Series(['0', '-0.02', '35', '. 3K', '-0.05K', '0' ]))
)
By running the below on various entries under the "Notional" column:
type(finalDf2.iloc[ , ]
I see the 0s are of type int already.
The nonzero values however are strings. I tried to convert strings to floats by using:
finalDf2['Notional'].astype(float)
but before doing so, how could I convert all cells containing "K" values? For instance,
. 3K should end up being float or int 30
-0. 05K should end up being float or int -50
Spacings are actually in the file and thus dataframe unfortunately.
. 3K should end up being float or int 30; -0. 05K should end up being float or int -50These 2 lines contradict eachother. should the space be converted to'0'or to''