简体   繁体   English

使用 python 将文本转换为带有逗号分隔符的列

[英]text to columns with comma delimiter using python

how to divide a column in to two columns in an excel using a delimiter ', 'and name the header's using python如何使用分隔符','将 excel 中的一列分成两列,并使用 python 命名标题

here is my code这是我的代码

import openpyxl


w=openpyxl.load_workbook('DDdata.xlsx')
active=w.active


a=active.columns[1]
for cellobj in a:
    s=cellobj.value
    fila=s.split(',')

    print(fila)

[Input file link][1] [输入文件链接][1]

[outputfile][3] [输出文件][3]

This looks to be a duplicate of this post , but here's a solution for you to consider:这看起来是这篇文章的副本,但这里有一个解决方案供您考虑:

import pandas as pd

df = pd.read_excel('input.xlsx')

df['First Name'], df['Last Name'] = df['Applicant Name'].str.split(',', 1).str
del df['Applicant Name']

df.to_excel('output.xlsx')

Output (in python):输出(在python中):

First Name  Last Name
0   -   Mohammed Abdul Naser Aziz
1   -   Gottipati Harshavardhan
2   -   Sandeep Kaur
3   .   Rounak
4   abbas   Syed
5   Abbas   Mohd Manzar
6   Abbasi  Fatema
7   Abdelkader  BEKHTIE
8   abdollahzadehkan    mina

Indeed sollution for The column is room type.列的确实解决方案是房间类型。 Next column is other Now the room type column should convert in to list and paste in other column下一列是其他 现在房间类型列应转换为列表并粘贴到其他列

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

相关问题 用逗号循环和 - 作为分隔符python - looping with comma and - as delimiter python 使用python在同一文件中用管道分隔符替换逗号 - Replace comma with pipe delimiter within the same file using python 如何使用 Python 使用 Pipe 分隔符拆分文本文件,然后根据条件选择列? - How to split text file with Pipe delimiter using Python and then pick columns based on condition? Python由逗号分隔符和带分隔 - Python split by comma delimiter and strip 使用Python将带分隔符的文本文件读取到sqlite - Reading Text file with delimiter to sqlite using Python 使用python使用分隔符解析文本文件 - Using python to parse through text file with delimiter Python/Pandas - 按分隔符将文本拆分成列; 并创建一个 csv 文件 - Python/Pandas - split text into columns by delimiter ; and create a csv file python pandas 中是否有一种方法可以像 excel 那样按位置(而不是通过分隔符)执行“文本到列”? - Is there a way in python pandas to do “Text to Columns” by location (not by a delimiter) like in excel? 如何将使用逗号作为分隔符但其中一列有逗号的文件导入熊猫? - How to import into pandas a file that is using a comma as delimiter but one of its columns has commas? Python:使用定界符写入csv文件的特定列 - Python: Using delimiter to write into specific columns of csv file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM