我有一个 csv 数据集,其中一些 id 是非常长的数字,如下所示:
963839330864351104
426545668232740352
811862613586429056
Run Code Online (Sandbox Code Playgroud)
当我读取 csv 并将数据集转换为数据框时,pandas 错误地认为它是一个数字并将其转换为科学通知,因此上面的数字变成了这样:
9.638393308643511e+17
4.2654566823274035e+17
8.11862613586429e+17
Run Code Online (Sandbox Code Playgroud)
我尝试通过将系列转换为 int64 来解决这个问题,这在大多数情况下都有效,但问题是:
有些数字原本可能是这样的
191268415833367997
Run Code Online (Sandbox Code Playgroud)
现在,当数字从科学记数法变为 int64(或 int)后,数字变成这样:
191268415833368000 #some how pandas think that it's ok to round the number up
Run Code Online (Sandbox Code Playgroud)
我需要的是让 pandas 明白数据集中保存这些 id 的列是一个字符串列,它不应该被视为数字,可能是在导入时,所以我不会将数字转换为整数,然后再转换为字符串当我格式化工作并转换我的数据集以满足我的需求时。
我尝试过以下操作但没有成功:
我看到这个问题以不同的方式被问到,但没有明确的答案或我能够理解的东西来适应我的问题。它应该是直截了当的,但不知怎的却并非如此。
非常感谢您的帮助。
菜鸟,过去一周我一直遇到这个问题,我不明白为什么 javascript 不会看到 code.gs 的返回值,因为我有相同的代码但不同的函数按预期工作。
是否有原因导致 Logger.log 中的日志值下方的 code.gs 函数意味着它有数据要返回,但 javascript 不会获取任何值并在警报中给我一个“null”?
代码.gs
function getInvoicesForID(studentAltID) {
  var invoicesForID = [];
  //get general invoices sheet and values
  var sInvoices = ss.getSheetByName("Invoices");
  var dataInvoices = sInvoices.getDataRange().getValues();
  //get balance info for id
  for(var i = 0; i < dataInvoices.length; i++){
    if(dataInvoices[i][4]==studentAltID){
      invoicesForID.push([dataInvoices[i][0],dataInvoices[i][1],dataInvoices[i][2],dataInvoices[i][3]]);
      break;
    }
  }
  Logger.log("invoicesForID = " + invoicesForID);
  return invoicesForID;
}
Run Code Online (Sandbox Code Playgroud)
javascript.html
  document.getElementById("btnsearchInvPayBalforStudentID").addEventListener("click",searchInvPayBalforStudentID);
//function to look for Payments, Invoices and Balance 
function searchInvPayBalforStudentID()
{
    try{
    //get the id 
      var stID = …Run Code Online (Sandbox Code Playgroud)