Python dataframe modifies a certain column type, several column types, and a certain column retains the specified position

Python dataframe
operates on the specified column
Operates on a column and column
Modify the data type of a column
Modify the data type of the specified column
A certain column retains the specified decimal
The specified column retains the specified decimal

insert image description here

import pandas as pd

df = pd.DataFrame({
    
    
    'v1':[1,2,3],
    'v2':[1.111,2.222,3.333]
})
df

df = df.astype({
    
    'v1':'float64'})
df

df.assign(v2=lambda df: round(df.v2,2))
df

Guess you like

Origin blog.csdn.net/qq_35240689/article/details/131244913