Pandas:不能删除列:ValueError:标签[<colname>]不包含在轴中

时间:2016-03-21 03:16:20

标签: python python-2.7 pandas dataframe

我有一个简单的CSV创建的df。当我尝试按名称引用列,合并到新的df或删除时,我得到了一个

<?php
$field_email = $_POST['email'];
$field_name = $_POST['name'];
$field_surname = $_POST['surname'];
$field_phone = $_POST['phone'];
$field_insurance = $_POST['insurance'];

$mail_to = 'info@teamworktowealth.com';
$subject = 'Message from a site visitor '.$field_email;

$body_message = 'First Name: '.$field_name."\n";
$body_message .= 'Last Name: '.$field_surname."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Insurance: '.$field_insurance."\n";

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
 <script language="javascript" type="text/javascript">;
  window.location.href ='http://www.thankyou.fidelisinsurancecompany.com';
 </script>
<?php
}
else { ?>
 <script language="javascript" type="text/javascript">
  alert('Registration failed. Please, send an email to info@fidelisltd.com');
  window.location = 'http://www.fidelisinsurancecompany.com';
 </script>
<?php
}
?>

我明白要删除列,必须使用

ValueError: labels [<colName>] not contained in axis

好像不知何时df被混淆了我的列是列,即使它们是顶行并且在iPython中查看时加粗。

1 个答案:

答案 0 :(得分:0)

首先索引它。

df.index = df[colName]