0

The code:

serie=df["TUTAR"].apply(lambda x: x.strip("'"))
df_s=serie.to_frame()
df_s.sort_values(by="Tutar",ascending=False)[0:50]

Hello friends, I have the "TUTAR" (Amount) column, a data frame consisting of float values ​​in " ". (For example: "12,5", "300,0") First I saved the values ​​from the " " sign. Then sorted it. But when sorting from largest to smallest, I did not get the correct result. How can I correctly sort the Float values ​​in a column of a data frame?

In the image below, the value 500 was supposed to come first, but it didn't. enter image description here

murat taşçı
  • 64
  • 1
  • 2
  • 22
  • Because they're not floats, they're strings (which just happen to contain numerals and a comma). After stripping the quotes, convert the column to a float type. – MatBailie Jul 18 '22 at 16:49
  • I tried df_s['TUTAR'] = df_s['TUTAR'].astype(float) but it didn't work – murat taşçı Jul 18 '22 at 16:58
  • Use locale and atof to parse your language's notation. Astype assumes commas as thousand separators and dots as decimal points. https://stackoverflow.com/questions/1779288 – MatBailie Jul 18 '22 at 16:59

1 Answers1

0
# Max Purchasing Value
serie=df["TUTAR"].apply(lambda x: x.strip("'"))
serie1=serie.apply(lambda x: x.replace(",","."))
df_s=serie1.to_frame()
df_s1=df_s.astype("float")
df_s1.sort_values(by="TUTAR",ascending=False)[0:50]

enter image description here

murat taşçı
  • 64
  • 1
  • 2
  • 22