Wie konvertiere ich Schwimmspalten ohne Dezimalzahl in Polare? [geschlossen]Python

Python-Programme
Anonymous
 Wie konvertiere ich Schwimmspalten ohne Dezimalzahl in Polare? [geschlossen]

Post by Anonymous »

Pandas-Code wie dieser, wenn eine Float-Spalte mit 1.0, 2.0, 3.0, entfernen

Code: Select all

df = pd.DataFrame({
"date": ["2025-01-01", "2025-01-02"],
"a": [1.0, 2.0],
"c": [1.0, 2.1],
})
print(df)
columns = df.columns.difference(["date"])
df[columns] = df[columns].map(lambda x: int(x) if x.is_integer() else x)
print(df)
< /code>
         date    a    c
0  2025-01-01  1.0  1.0
1  2025-01-02  2.0  2.1
date  a    c
0  2025-01-01  1  1.0
1  2025-01-02  2  2.1

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post