我有一个csv文件,当作为熊猫数据帧读入时,它看起来像这样:
OBJECTID_1 AP_CODE
0 857720 137t62t005tNE
1 857721 137t62t004tNW
2 857724 137t62t004tNE
3 857726 137t62t003tNE
4 857728 137t62t003tNW
5 857729 137t62t002tNW
df.info() 返回以下内容:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 9313 entries, 0 to 9312
Data columns (total 2 columns):
OBJECTID_1 9312 non-null float64
AP_CODE 9313 non-null object
dtypes: float64(1), object(1)
memory usage: 181.9+ KB
None
和print(repr(open(r'P:file.csv').read(100)))
返回以下内容:
'OBJECTID_1,AP_CODEn857720,"137t62t005tNE"n857721,"137t62t004tNW"n857724,"137t62t004tNE"n857726,"137t'
我想摆脱列中的t
AP_CODE
但我无法弄清楚它为什么存在,或者如何删除它。 .replace
不起作用。
如果要
使用制表符替换,则需要使用原始字符串,方法是将字符串文本与r
一起预置:
In [299]: df.AP_CODE.str.replace(r'\t',' ')
Out[299]:
0 137 62 005 NE
1 137 62 004 NW
2 137 62 004 NE
3 137 62 003 NE
4 137 62 003 NW
5 137 62 002 NW
Name: AP_CODE, dtype: object