DataFrame 指定某列的格式

import pandas as pd

# 创建示例 DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25.0, 30.0, 35.0]  # 注意:这里的年龄列是浮点数类型
}
df = pd.DataFrame(data)

# 将 'Age' 列的数据类型设置为整数
df['Age'] = df['Age'].astype(int)

print("DataFrame with 'Age' column as integer:")
print(df.dtypes)
print(df)

 

posted @ 2023-08-08 15:11  OTAKU_nicole  阅读(191)  评论(0编辑  收藏  举报