第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

協(xié)助將數(shù)據(jù)框拆分為新列

協(xié)助將數(shù)據(jù)框拆分為新列

素胚勾勒不出你 2023-07-27 16:31:40
我在用 _ 分割數(shù)據(jù)框并從中創(chuàng)建新列時(shí)遇到問題。原來的股AMAT_0000006951_10Q_20200726_Item1A_excerpt.txt    as section我當(dāng)前的代碼df = pd.DataFrame(myList,columns=['section','text'])#df['text'] = df['text'].str.replace('?','')df['section'] = df['section'].str.replace('Item1A', 'Filing Section: Risk Factors')df['section'] = df['section'].str.replace('Item2_', 'Filing Section: Management Discussion and Analysis')df['section'] = df['section'].str.replace('excerpt.txt', '').str.replace(r'\d{10}_|\d{8}_', '')df.to_csv("./SECParse.csv", encoding='utf-8-sig', sep=',',index=False)輸出:section                                 textAMAT_10Q_Filing Section: Risk Factors_  The COVID-19 pandemic and global measures taken in response                                         thereto have adversely impacted, and may continue to adversely                                         impact, Applied’s operations and financial results.AMAT_10Q_Filing Section: Risk Factors_  The COVID-19 pandemic and measures taken in response by                                         governments and businesses worldwide to contain its spread,                                         AMAT_10Q_Filing Section: Risk Factors_  The degree to which the pandemic ultimately impacts Applied’s                                         financial condition and results of operations and the global                                         economy will depend on future developments beyond our control我真的很想以某種方式拆分“部分”,將其放入基于“_”的新列中我已經(jīng)嘗試了許多不同的正則表達(dá)式變體來拆分“部分”,并且所有這些都給了我沒有填充的標(biāo)題或者他們?cè)诓糠趾臀谋局筇砑恿肆?,這是沒有用的。我還應(yīng)該補(bǔ)充一下,大約有 100,000 個(gè)觀察結(jié)果。期望的結(jié)果:Ticker  Filing type  Section                       TextAMAT    10Q          Filing Section: Risk Factors  The COVID-19 pandemic and global measures taken in response 任何指導(dǎo)將不勝感激。
查看完整描述

1 回答

?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果您始終知道分割數(shù),您可以執(zhí)行以下操作:


import pandas as pd


df = pd.DataFrame({ "a": [ "test_a_b", "test2_c_d" ] })


# Split column by "_"

items = df["a"].str.split("_")


# Get last item from splitted column and place it on "b"

df["b"] = items.apply(list.pop)


# Get next last item from splitted column and place it on "c"

df["c"] = items.apply(list.pop)


# Get final item from splitted column and place it on "d"

df["d"] = items.apply(list.pop)


這樣,數(shù)據(jù)框?qū)⒆兂?/p>


           a  b  c      d

0   test_a_b  b  a   test

1  test2_c_d  d  c  test2

由于您希望列按特定順序排列,因此可以對(duì)數(shù)據(jù)框的列重新排序,如下所示:


>>> df = df[[ "d", "c", "b", "a" ]]

>>> df

       d  c  b          a

0   test  a  b   test_a_b

1  test2  c  d  test2_c_d


查看完整回答
反對(duì) 回復(fù) 2023-07-27
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)