Python:将null替换为0

问题描述

将Python数据框中的所有空“ NaN”值替换为0的最佳方法是什么?

还可以通过for循环来做到这一点吗?

解决方法

您可以简单地使用

const { Sequelize,DataTypes } = require('sequelize');

const sequelize = new Sequelize({
    host: "127.0.0.1",port: 5432,database: "mydb",username: "myusername",password: "mypassword",dialect: "postgres",logging: console.log,});

const schemaName = 'aschema';

async function main() {

    ////////////////////////////////////////////////////////////
    // Establish the connection
    await sequelize.authenticate();
    console.log('Connection has been established successfully.');

    ////////////////////////////////////////////////////////////
    // Create db schema
    await sequelize.createSchema(schemaName);

    ////////////////////////////////////////////////////////////
    // Define models

    const Company = sequelize.define('company',{
        id: {
            type: DataTypes.INTEGER,allowNull: false,primaryKey: true,autoIncrement: true
        },name: {
            type: DataTypes.STRING,allowNull: false
        },},{
        schema: schemaName,// freezeTableName: true,tableName: 'company'
    });

    const User = sequelize.define('user',name: {
            type: DataTypes.STRING
        },companyId: {
            type: DataTypes.INTEGER
        },// aNewPotentialField: {
        //     type: DataTypes.INTEGER
        // }
    },tableName: 'user'
    });

    ////////////////////////////////////////////////////////////
    // Set relations
    User.belongsTo(Company,{ as: 'company',foreignKey: 'companyId' });
    // Company.hasOne(User,{ as: 'users',foreignKey: 'companyId' });

    // User.belongsTo(Company);
    ////////////////////////////////////////////////////////////
    // Sync

    // * These syncs below multiply the existing relations.
    // * Will add the field 'aNewPotentialField' in the future since alter set to true.
    await Company.sync({ alter: true });
    await User.sync({ alter: true });

    // * These syncs below don't multiply the existing relations.
    // * However,also wont add the field 'aNewPotentialField' in the future since alter set to false.
    // await Company.sync();
    // await User.sync();

    ////////////////////////////////////////////////////////////
    // Close the established connection.
    await sequelize.close();
    ////////////////////////////////////////////////////////////
}


main()
    .then(() => {
        console.log('App started successfully.');
    })
    .catch((e) => {
        throw e;
    });

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...