简体   繁体   English

如何删除 pandas dataframe 中的分隔符列

[英]How to remove delimiter column in the pandas dataframe

I have the following dataset in.csv file我在.csv 文件中有以下数据集

when i read the file i get something like this当我阅读文件时,我得到了类似的东西

df = pd.read_csv("xxx.csv",dtype = str ,header = None, encoding='utf-8')
df.head()
0   1   2   3   4   5  6 
63  |   ssd |   23  | 4kj
63  |   ssd |   30  | 4rc
63  |   ssd |   900 | 4rt
63  |   ssd |   100 | Bqa
63  |   ssd |   140 | 8er
63  |   ssd |   10  | 8df
63  |   ssd |   40  | Bfr

As in the above dataframe 0,1,2,3,4,5,6.如上 dataframe 0,1,2,3,4,5,6。 when i read the XXX.csv file i just need the column with the information i don't want the column with the delimiter.当我阅读 XXX.csv 文件时,我只需要包含信息的列,我不想要带有分隔符的列。

expected output预计 output

    0    1   2  3
    63  ssd 23  4kj
    63  ssd 30  4rc
    63  ssd 900 4rt
    63  ssd 100 Bqa
    63  ssd 140 8er
    63  ssd 10  8df
    63  ssd 40  Bfr

How can i get this while reading XXX.csv file我如何在阅读 XXX.csv 文件时得到这个

I don't want to use df = df.drop('column_name', 1) as my data will be dynamic.我不想使用df = df.drop('column_name', 1)因为我的数据是动态的。

I want to get rid of delimiter column while reading XXX.csv file.我想在读取 XXX.csv 文件时去掉分隔符列。

Please help on this regard.请在这方面提供帮助。

have you try this.你试试这个。 ? ?

import pandas as pd

df = pd.read_table('file.csv', delimiter='|')

df = pd.read_csv('file.csv', sep='|')

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

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