-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Closed
Labels
Closing CandidateMay be closeable, needs more eyeballsMay be closeable, needs more eyeballsEnhancementIO Excelread_excel, to_excelread_excel, to_excel
Description
Feature Type
-
Adding new functionality to pandas
-
Changing existing functionality in pandas
-
Removing existing functionality in pandas
Problem Description
Excel interprets text values starting with '=' as formula.
It can happen that values in a pandas Series (col of data frame) might start with '=' (for example '=== Attention ===').
If this is faced by excel:
- In case of valid formula, it is interpreted
- In case of invalid formula, the file is corrupted and the values are null after attempt to fix
We should handle this better
Feature Description
If the value starts with '=', issue a warning and add a single quote prefix to the value:
Before: === Attention ===
After: '=== Attention ==='
Alternative Solutions
For columns with object dtypes, or categories with underlying object dtype, for values which are strings, force the excel format as text.
Additional Context
- The proposed ' prefix is not 100% correct: when we prefix any text with a ' in excel, it is interpreted as text. Unfortunatety, the proposal will show the ' (see example code below)
- It might be problematic if people wants to clearly use formula, but I don't think that's really meaningful. Maybe an option to avoid that conversion (but issue the warning anyway) can be a good option
- Example code:
import pandas as pd
df = pd.DataFrame([
"foo",
"bar",
"baz",
"=== Attention ===", # Problem
"'===Attention ===" # OK but the single quote will be displayed
])
df.to_excel('demo.xlsx')
Metadata
Metadata
Assignees
Labels
Closing CandidateMay be closeable, needs more eyeballsMay be closeable, needs more eyeballsEnhancementIO Excelread_excel, to_excelread_excel, to_excel