使用python使用逗号分隔符将文本转换为列 [英] text to columns with comma delimiter using python
本文介绍了使用python使用逗号分隔符将文本转换为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Excel中使用分隔符','将一列分为两列,并使用python命名标题
how to divide a column in to two columns in an excel using a delimiter ', 'and name the header's using python
这是我的代码
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)
[输入文件链接] [1]
[Input file link][1]
[输出文件] [3]
[outputfile][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')
输出(在python中):
Output (in 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
这篇关于使用python使用逗号分隔符将文本转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文