Home > other >  Not all the arguments converted during string formatting
Not all the arguments converted during string formatting

Time:11-04

Df1=pd. DataFrame (np) random) randn (5, 5), the columns=list (" abcde "))
Df1. Applymap (lambda x: '2' f % x)
Want to format the generated random Numbers, only to get this error, how to return a responsibility

CodePudding user response:

The format string, lack the %
The changed code is as follows:
 import numpy as np 
Df1=pd. DataFrame (np) random) randn (5, 5), the columns=list (" abcde "))
Print (df1)
Df1=df1. Applymap (lambda x: x % %. 2 f)
Print (df1)

The results are as follows:
A b c d e
0 0.841073 0.167431 0.273329 0.209956 1.045138
1 0.203088 0.535447 0.541680 0.272025 0.269669
2-0.890863-0.765354-2.394559-0.662201 0.180201
3-1.059926-1.729437-0.627603-0.085897 0.391459
4 0.205721 1.574832 1.688674 0.454605 0.615806
A b c d e
0 0.84 0.17 0.27 0.21 1.05
1 0.20 0.54 0.54 0.27 0.27
2-0.89-0.77-2.39-0.66 0.18
3-1.06-1.73-0.63-0.09 0.39
4 0.21 1.57 1.69 0.45 0.62
  • Related