'How to transform/format scientific notation number to 2 decimal cases?
I have this function below, that iterates through sheets in a excel workbook, and gets the data into a pandas dataframe. Unfortunately some of the values are coming in scientific notation, and I need them rounded to 2 decimal cases
def iterate_sheets(wb, number_of_fw=13):
# iterates through each sheet in the workbook
for sheet in wb.sheetnames:
ws = wb[f'{sheet}']
i = 0
while i < number_of_fw:
cel = ws[f'A{10 + i}']
cel.number_format = '#,##0.00'
fiscal_weeks.append(cel.value)
i += 1
i = 0
print(fiscal_weeks)
while i < number_of_fw:
cel = ws[f'B{10 + i}']
cel.number_format = '#,##0.00'
pageloads.append(cel.value)
i += 1
i = 0
print(pageloads)
while i < number_of_fw:
cel = ws[f'C{10 + i}']
cel.number_format = '#,##0.00'
tti.append(cel.value)
i += 1
print(tti)
platform_name = ws["B2"].value
metric_name = ws["C8"].value
# transform the data into a pandas DataFrame
data_dict = {
'fiscal_week': fiscal_weeks,
'pageload': pageloads,
'tti': tti,
'metric_name': metric_name
}
df = pd.DataFrame(data_dict)
Solution 1:[1]
You can try this:
pd.set_option('display.float_format', lambda x: '%.2f' % x)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yeyosef |
