尝试将 csv 文件读入我的数据类型时出现值错误。我需要确保它有效并且每一行都被读入并且是正确的。
错误例如:
Pandas: ValueError: Integer column has NA values in column 2
Run Code Online (Sandbox Code Playgroud)
我试图在 Pandas Python 库中转换为整数,但有一个值。
但是,我读入的 csv 文件似乎有一些错误的条目,因为它由手动输入的测试结果组成。
我读到使用这个命令:
test = pd.read_csv("test.csv", sep=";", names=pandasframe_names, dtype=pandasframe_datatypes, skiprows=1)
Run Code Online (Sandbox Code Playgroud)
名称为 A、B、C、D 和 E,并且定义正确。
如果有错误的条目,我需要一种处理此问题而不丢失整行的方法。
这是我的情况:我有一个 pandas 数据框,它读取 csv 表,该表有 5 列,标题为 A、B、C、D、E。我使用参数skiprows=1 跳过第一行
pandas_datatypes={'A': pd.np.int64, 'B':pd.np.int64, 'C':pd.np.float64, 'D':object, 'E':object}
Run Code Online (Sandbox Code Playgroud)
我的行有 5 列,前 2 列是 int64,第三列是 float64,接下来的 2 列是对象(例如字符串)
当我读入它时,这些相当于我的数据类型。含义dtype=pandas_datatypes
现在我有这样的条目:
entry 1: 5; 5; 2.2; pedagogy; teacher (correct)
entry 2: 8; 7.0; 2.2; pedagogy; teacher (incorrect, as second is …Run Code Online (Sandbox Code Playgroud) 我已经使所有整数无符号但我仍然得到错误.我需要改变什么?
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFacebook extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('facebook', function($table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
$table->string('username', 255);
$table->bigInteger('uid', 20)->unsigned();
$table->string('access_token', 255);
$table->string('access_token_secret', 255);
$table->string('photoURL', 255);
$table->string('profileURL', 255);
$table->string('firstName', 255);
$table->string('lastName', 255);
$table->string('gender', 255);
$table->string('age', 20);
$table->integer('birthDay')->unsigned();
$table->integer('birthMonth')->unsigned();
$table->integer('birthYear')->unsigned();
$table->string('email', 255);
$table->string('phone', 30);
$table->string('address', 255);
$table->string('country', 100);
$table->string('region', 100);
$table->string('city', 100);
$table->string('zip', 20);
});
}
/**
* Reverse the migrations.
*
* @return void …Run Code Online (Sandbox Code Playgroud)