4
我有我这个代码打开.xlsx文件:Python的方式来过滤列,然后创建一个新的列
import pandas as pd
df = pd.read_excel(open('file.xlsx','rb'))
df['Description'].head
,我有以下结果,这看起来不错。
ID | Description
:----- | :-----------------------------
0 | Some Description with no hash
1 | Text with #one hash
2 | Text with #two #hashes
现在我想创建一个新的列,只保留字开始#,像这样的:
ID | Description | Only_Hash
:----- | :----------------------------- | :-----------------
0 | Some Description with no hash | Nan
1 | Text with #one hash | #one
2 | Text with #two #hashes | #two #hashes
我能数/单独的行以#:
但现在我想创建像我上面描述的列。什么是最简单的方法来做到这一点?
问候!
PS:它应该显示问题中的表格格式,但我无法弄清楚它为什么显示错误!
这种解决方案更优雅! – MaxU