【问题标题】:How to remove the last character from a column of data from a CVS file?如何从 CVS 文件的数据列中删除最后一个字符?
【发布时间】:2019-10-15 17:51:44
【问题描述】:

我正在尝试使用具有 3 列数据的 csv 文件进行线性关系。不幸的是,我无法读取第三列(最后一列为 int,因为它在每个值的末尾都有一个';'。例如213124121;1231231; 等。

data["the price;"] = df['the price;'].astype('int64') 

错误:

ValueError: invalid literal for long() with base 10: '399900; '

如何删除整列的';'

【问题讨论】:

    标签: python python-2.7 dataframe


    【解决方案1】:

    你可以简单的改变 df['the price;']df['the price;'][:-2]

    它在python中称为字符串切片,您可以在here阅读更多信息

    感谢@stovfl在我的回答中发现错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-12
      • 1970-01-01
      • 2013-09-22
      • 2021-12-11
      • 2011-11-18
      相关资源
      最近更新 更多