简体   繁体   English

如何在列中组合两个条目值

[英]How to combine two entry values in a column

In the dataset, the column "Erf Size" has entries like 1 733 and 1 539 etc. Note that the Dtype of this "Erf Size" column is object.在数据集中,“Erf Size”列有 1 733 和 1 539 等条目。请注意,“Erf Size”列的 Dtype 是 object。

I would like to join these 1 733 and 1 539 into 1733 and 1539 etc. original dataset我想将这些 1 733 和 1 539 加入 1733 和 1539 等原始数据集

expected output预计 output

I think you can fix this with pd.to_numeric .我认为您可以使用pd.to_numeric解决此问题。 This will change the data type to a number value and I expect it to remove the space.这会将数据类型更改为数字值,我希望它可以删除空格。

Or else you can try:否则你可以试试:

df1['Erf Size'].str.strip()

that will remove the space, which will work in your dataset as it's an object.这将删除空间,这将在您的数据集中工作,因为它是 object。

I would use list comprehension to clean string and then if you want to can convert dtype to numeric value:我会使用列表理解来清理字符串,然后如果你想可以将 dtype 转换为数值:

df['Erf Size'] = [x.replace(' ', '').replace('.', '').replace(',', '') for x in df['Erf Size']]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM