简体   繁体   English

如何使用 python 将 2 列相似数据连接到具有相同列标题的同一 excel 文件中的单个列中

[英]How to join 2 columns of similar data into a single column in a same excel file with same column headings using python

In this image i had 4 columns with repeated column names.在这张图片中,我有 4 列具有重复的列名。 i needed only 2 columns one for item and one for amount with all the values in only 2 columns.Can anyone please help me out.Thanks in advance.我只需要 2 列,一列用于项目,一列用于数量,所有值都在 2 列中。任何人都可以帮助我。提前致谢。

数据样本

If you can read 2 columns here, read 4 columns at a time.如果您可以在此处阅读 2 列,则一次阅读 4 列。 Access by their index.通过他们的索引访问。 Assuming it's a CSV file,假设它是一个 CSV 文件,

import csv
rows = []
with open('file.csv') as csvfile:
    reader = csv.reader(csvfile, ...)
    for row in reader:
         item_amount1 = row[1:3]
         item_amount2 = row[3:5]
         rows.extend([item_amount1, item_amount2])

暂无
暂无

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

相关问题 如何使用python具有相同的列和行标题? - How to have same column and row headings using python? 通过更改标题将.csv文件中的单个列拆分为多个列,并使用Python 2将其保存到新的.csv文件中 - Splitting a single column in a .csv file into multiple columns with changes in headings and saving it in a new .csv file using Python 2 如果列没有标题,如何使用 python 分隔一列 CSV 文件,然后将其保存到新的 excel 文件中? - How to use python to seperate a one column CSV file if the columns have no headings, then save this into a new excel file? 如何在 Python 中将整列数据(行数不固定)复制到同一个 Excel 文件中的新列? - How can I copy an entire column of data (the number of rows are not fixed) to a new column in the same excel file, in Python? 如何使用 Pandas 按单列分组并在 excel 中打印相同的内容 - How to groupby a single column and print the same in excel using Pandas 如何使用 python 脚本将 excel 中的多列复制到单列 - How to copy multiple columns to single column in excel using python script 使用 python 在 excel 文件的不同列中查找相同的单词 - Finding same word in different column on excel file using python 如何在python中使用pandas连接同一列中的项目? - How to join items from same column using pandas in python? Python - 如何使用列标题从CSV数据文件创建字典 - Python - How to Create Dictionary from CSV data file using column headings 如何使用 python 脚本将一行中存在的数据(以空格分隔)拆分为同一 excel 工作表中的不同列? - How to split data present in a row (separated by space) into different column in the same excel sheet using python script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM