I have a dataset, df, where I wish to convert several columns from bytes to TB and MB to TB.
Free Total
30,000,000,000,000.00 40,000,000
40,000,000,000,000.00 50,000,000
Bytes to TB - divide by 1024/1024/1024/1024 Megabytes to TB - divide by 1024/1024
Desired Output
Free Total Used
30 40 10
40 50 10
This is what I am doing
import pandas as pd
import numpy as np
df = pd.read_csv("df.csv")
df['Free'] = df['Free'].astype(str).str.replace(',','').astype(float).div(1000000000000)
df['Total'] = df['Total'].astype(str).str.replace(',','').astype(float).div(1000000)
df['Used'] = df['Total'] - df['Free']
My code above is not retaining the original dataset nor is it giving me my desired output. Any suggestion is appreciated.