如何取消Pandas DataFrame列的科学计数法格式
accountnumber Column in Pandas Got it, let's figure out why your current approach didn't work and get that accountnumber column looking right. The pd.options.display.float_format you tried only changes how data shows up in your notebook/console—it doesn't fix the underlying data type or values, which is why you didn't see the effect you wanted.
Here are a few reliable solutions tailored to different scenarios:
Solution 1: Read the column as a string upfront (most foolproof)
When loading your CSV, tell Pandas to treat accountnumber as a string instead of letting it auto-convert to a float. This preserves the original numeric format entirely, so scientific notation never becomes an issue:
df = pd.read_csv('data.csv', dtype={'accountnumber': str})
This is the best approach if you don't need to do math on the account numbers (which you probably don't!).
Solution 2: Convert an existing float column to integer strings
If you've already loaded the data and need to fix the column retroactively:
Your values look like integers (e.g., 4.11889000e+11 translates to 411889000000 as a whole number), so first convert the float to an integer to drop the decimal part, then turn it into a string to lock in the format:
# Convert float to integer (this handles the scientific notation conversion) df['accountnumber'] = df['accountnumber'].astype(int) # Convert to string to avoid any accidental re-formatting later df['accountnumber'] = df['accountnumber'].astype(str)
If you're worried about edge cases (like non-integer values slipping in), use safer conversion with pd.to_numeric:
df['accountnumber'] = pd.to_numeric(df['accountnumber'], downcast='integer').astype(str)
Solution 3: Fix display without changing the underlying data
If you only care about how the column looks when you print it, not the data type itself, adjust your float format to show whole numbers instead of 3 decimal places:
# Apply to all float columns globally pd.options.display.float_format = '{:.0f}'.format # Or target just the accountnumber column df['accountnumber'] = df['accountnumber'].apply(lambda x: '{:.0f}'.format(x))
This will render the values as plain whole numbers, though the data might still be stored as a float in the background.
内容的提问来源于stack exchange,提问作者iprof0214

