【发布时间】:2021-12-19 00:48:58
【问题描述】:
我正在使用 python,我读取了一个文件,我想从相同的问题中删除重复项,但它一直在读取名称为 1 的重复项。
例如:有 2 个 question1 它读取它们 question1 和 question1.1
所以当我使用 .drop_duplicates() 时它什么也没做,这里有什么问题?
file = 'survey.csv'
responses = pd.read_csv(file,header=1)
responses.head()
responses.drop_duplicates()
这是 .cvs 文件的示例
> ,,,X,,,,,,,,,,,,,,,,
> Timestamp,Email Address,,"Know about basic linear algebra and matrices operations (multiplication, add, transpose)?",Know how to
> apply differentiation and the chain rule?,Know how to apply
> differentiation and the chain rule?,"Know what is a probability
> distribution and density function, and how to sample it?","Know what
> is a probability distribution and density function, and how to sample
> it?",Know the difference between classification and regression?,Know
> the difference between training and testing data?,Know the difference
> between training and testing data?,Know what is a training loop and
> what is an epoch?,Know what is a batch?,Know what is
> regularization?,Know what is overfitting and underfitting?,Know what
> is a feature vector?,,,,
> ,,,,,,,,,,,,,,,,,,,
> 10/14/2021 17:15:05,y.sedki@gmail.com,,Yes,Yes,Yes,Yes,Yes,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,,,,
> 10/14/2021 17:15:39,k.abdulaal@hotmail.com,,Yes,Yes,Yes,Yes,Yes,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,,,,
但是上面的代码写完后的输出是
> Know how to apply differentiation and the chain rule? Know how to > apply differentiation and the chain rule?.1
【问题讨论】:
-
我认为它不会自行将
question1更改为question1.1。确定不在文件中?显示文件内容示例。 -
@Barmar 列名默认情况下会被破坏以防止重复。 read_csv 有
mangle_dupe_cols=True不清楚问题是指 列标题 重复还是列数据重复。我同意 csv 样本会有所帮助。也不清楚我们是否没有遇到this issue,这取决于我们期望responses.drop_duplicates()做什么 -
如果您的
header=1。第一行是什么? -
@Barmar 这里是一个示例:,,,X,,,,,,,,,,,,,,,, Timestamp,Email Address,,"了解基本的线性代数和矩阵运算?",知道如何应用微分和链式法则吗?,知道如何应用微分和链式法则吗?,"知道什么是概率分布和密度函数,以及如何对其进行采样?",
-
@HenryEcker 我以为他说的是重复数据,而不是重复的列名。
标签: python pandas csv jupyter-notebook duplicates