繁体   English   中英

如何将用逗号分隔的单词(txt 文件)重新排列为 pandas 中的单词列表?

[英]How do I rearrange words separated with comma (txt file) to list of words in pandas?

我有一个txt文件写成

a,b,c,d,e ...

如何在 python 中阅读此内容并按以下格式重新排列?

a
b
c
d
e

非常感谢..

如果你只想转置你可以使用:

pd.read_csv('<Name of your csv file here>', header= None).T.to_csv('test.txt', index =False, header =None)
>>> pd.Series(open("dummy.txt").read().rstrip().split(','))
0    a
1    b
2    c
3    d
4    e
dtype: object

暂无
暂无

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

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