小编Oll*_*ani的帖子

什么时候适合使用df.value_counts()vs df.groupby('...').count()?

我听说熊猫经常有多种方法可以做同样的事情,但我想知道 -

如果我尝试按特定列中的值对数据进行分组并计算具有该值的项目数,则何时使用df.groupby('colA').count()以及何时使用有意义df['colA'].value_counts()

python dataframe pandas pandas-groupby

15
推荐指数
2
解决办法
2万
查看次数

Sequelize seeder:意外的标识符错误,没有堆栈跟踪进一步解释它

我在使用 Sequelize 时遇到问题,sequelize:seed使用 autoIncrement 键运行 Postgres 会破坏向该表添加新项目的能力。Sequelize 不会自动将模型与表中的最新 id 同步,因此在添加种子数据后出现重复的关键错误。

我试图用我在这里找到的一些关于种子文件运行后重新同步序列的建议来修复它,但我收到错误Unexpected Identifier并且没有进一步的解释。

这是我的代码 - 谁能告诉我出了什么问题吗?我的 linter 没有抛出任何错误,所以我不认为这是标准语法错误:

'use strict';
const db = require('../models');

module.exports = {
  up: async (queryInterface, Sequelize) => {
    /*
      Add altering commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.bulkInsert('People', [{
        name: 'John Doe',
        isBetaMember: false
      }], {});
    */
    return await queryInterface
      .bulkInsert('user_podcasts', [
        {
          id: 1,
          userId: 1,
          podcastId: '88b15eefe35d42c58bca9c5e17080661',
          createdAt: new Date().toISOString(),
          updatedAt: new Date().toISOString() …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js sequelize.js

4
推荐指数
1
解决办法
2921
查看次数

无法使用护照和谷歌oauth策略访问谷歌登录页面

我正在尝试使用 Passport 让用户能够使用他们的 Google 帐户登录网络应用程序,但我似乎无法获取我的登录路由 /auth/google,甚至无法重定向到 Google 登录页面。我的其他路线工作正常,我的控制台中没有收到任何错误,但是当我转到 localhost:5000/auth/google 时,页面只是挂起并最终给出“localhost 拒绝连接”错误(我假设之后已超时)。

知道会发生什么吗?我已经在另一个应用程序中成功地使用了基本上完全相同的代码 - 我知道我还没有设置大部分用于完全登录的脚手架,但我认为此时至少应该加载谷歌登录页面。

索引.js

import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import passport from 'passport';
const GoogleStrategy = require('passport-google-oauth20').Strategy;

// import database from './server/src/models';
import userRoutes from './server/routes/UserRoutes';

const PORT = process.env.PORT | 5000;
const app = express();

passport.use(
  new GoogleStrategy(
    {
      clientID: process.env.googleClientID,
      clientSecret: process.env.googleClientSecret,
      callbackURL: '/auth/google/callback'
    },
    (accessToken, refreshToken, profile, cb) => {
      console.log(accessToken);
    }
  )
);

app.use(cors());
app.use(bodyParser.json());
app.use(passport.initialize());
app.use(passport.session());

app.get('/', …
Run Code Online (Sandbox Code Playgroud)

node.js express google-oauth passport.js passport-google-oauth2

1
推荐指数
1
解决办法
3543
查看次数