0

I need some transform about numbers like 100000 to 100.000 in Python. How can I do that ?

I tried it with using Format(number,'.d'). But I have DataFrame, or List. When I execute the code, it says unsupported format string passed to numpy.ndarray.format

users = data.iloc[:,[3]].values.astype(str)


for i in range(len(users)):
    users[i] = (format (users[i], ',d')) 
users[i] = (format (users[i], ',d'))

TypeError: unsupported format string passed to numpy.ndarray.format

yatu
  • 86,083
  • 12
  • 84
  • 139
B. Ozen
  • 63
  • 10

2 Answers2

1

Here's an alternative way to achieve what you're trying to do without using the format function but relying on locale module instead:

import pandas
import locale
locale.setlocale(locale.LC_ALL, 'de_DE.utf-8')

users = pandas.DataFrame(data=[100, 1000, 10000, 100000], columns=["colA"])
users["colA"] = [locale.format("%d", v, 1) for v in users.iloc[:,0]]
print(users)

Outcome:

      colA
0      100
1    1.000
2   10.000
3  100.000
Artur
  • 407
  • 2
  • 8
0

You're applying format on a series basically, not specifying the axis either.

Try this, it'll add comma(s) to all the values in 3rd column:

df.iloc[:,[3]] = df.iloc[:,[3]].apply(lambda x:format (x.values[0], ',d'), axis=1)
Arsal
  • 447
  • 2
  • 6