About Lesson
Join the conversation
import numpy as np
kbs = 1024 # example value in KB
mbs = np.round(kbs / 1024, 2)
print(mbs
Reply
assignment done.
Reply
Here is my assignment link: https://colab.research.google.com/drive/1JUTEkTyliHUTXn8NvuuO9gqcPDuSOZ5F
Reply
Sir I Done with the code => def convert_to_mb(size):
if size.endswith('k'):
return str(round(float(size[:-1]) / 1024)) + 'M'
else:
return size
df['Size'] = df['Size'].apply(convert_to_mb)
df.head(10)it work 100%
Reply
I have read both blogs, but "Missing values ka rola" was very informative and attention-grabbing and warned me not to ignore missing values in any case.
Reply
# Assuming you have a DataFrame df and a column 'size_MB' containing sizes in MB
df['size_KB'] = df['size_MB'] * 1024
To convert Mbs to kbs in pyhton using pandas
Reply
import pandas as pd df = ... # your dataframe df['Size'] = df['Size'].str.lower() def convert_to_mb(size): if size[-1] == 'k': return f"{float(size[:-1]) * 1024/1024} Mb" else: return size df['Size'] = df['Size'].apply(convert_to_mb)
Reply
import pandas as pddf = ... # your dataframedf['Size'] = df['Size'].str.lower()def convert_to_mb(size):
if size[-1] == 'k':
return f"{float(size[:-1]) * 1024/1024} Mb"
else:
return size
df['Size'] = df['Size'].apply(convert_to_mb)
Reply
https://colab.research.google.com/drive/1AJ6tHeg7jCyJtt0TT6qa-ZZZQDgsVbeA?usp=sharing
Reply
Removing $ sign from Price columndf['Price'] = pd.to_numeric(df['Price'].str.replace('[$,]', '', regex=True), errors='coerce').fillna(0)non numeric value are filled with 0
Reply