目前,我正试图在每次';;'时拆分第一行。出现在“材料描述”列中的新行中。导致这一点的代码是:
df.loc[df['mask'] == True, ['Material Description']] = ';;' + df['Material Description']
df['Material Description'] = df['Material Description'].str.cat()
df['Material Description'].tolist()
df['Material Description'].str.split(';;')
我尝试过的代码就是对此代码的操作,但是我似乎无法解决。
pd.concat([Series(row['var2'], row['var1'].split(','))
for _, row in a.iterrows()]).reset_index()
Material Description
0 Hello;; How are you doing;; This is good
1
2
获得所需的输出:
Material Description
0 Hello
1 How are you doing
2 This is good
参考方案
你可以改变:
df['Material Description'].str.split(';;')
至:
df1 = (df['Material Description'].str.split(';;', expand=True)
.stack()
.reset_index(drop=True)
.to_frame('Material Description'))
print (df1)
Material Description
0 Hello
1 How are you doing
2 This is good
解释:
如果将expand=True
添加到 Series.str.split
中以获得DataFrame
,则通过 DataFrame.stack
进行整形,最后通过 DataFrame.reset_index
进行一些数据清理,对于一列DataFrame
使用 Series.to_frame
我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…
Python exchangelib在子文件夹中读取邮件 - python我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…
python JSON对象必须是str,bytes或bytearray,而不是'dict - python在Python 3中,要加载以前保存的json,如下所示:json.dumps(dictionary)输出是这样的{"('Hello',)": 6, "('Hi',)": 5}当我使用json.loads({"('Hello',)": 6,…
R'relaimpo'软件包的Python端口 - python我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。
Python ThreadPoolExecutor抑制异常 - pythonfrom concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…