
import pandas as pd
d = pd.DataFrame(['a', 'b', 'c'],columns = ['A'])
d
A | |
---|---|
0 | a |
1 | b |
2 | c |
將某列元素拼接一列特定字符串
d['A'].str.cat(['A', 'B', 'C'], sep=',')
0 a,A
1 b,B
2 c,C
Name: A, dtype: object
將某列的元素合并為一個(gè)字符串
d['A'].str.cat(sep=',')
'a,b,c'
import numpy as np
import pandas as pd
d = pd.DataFrame(['a_b_c', 'c_d_e', np.nan, 'f_g_h'],columns = ['A'])
d
A | |
---|---|
0 | a_b_c |
1 | c_d_e |
2 | NaN |
3 | f_g_h |
將某列的字符串元素進(jìn)行切分
d['A'].str.split('_')
0 [a, b, c]
1 [c, d, e]
2 NaN
3 [f, g, h]
Name: A, dtype: object
d = pd.DataFrame(['a_b_c', 'c_d_e', np.nan, 'f_g_h'],columns = ['A'])
d['A']
0 a_b_c
1 c_d_e
2 NaN
3 f_g_h
Name: A, dtype: object
d['A'].str.get(2)
0 b
1 d
2 NaN
3 g
Name: A, dtype: object
d = pd.DataFrame(['a_b_c', 'c_d_e', np.nan, 'f_g_h'],columns = ['A'])
d['A']
0 a_b_c
1 c_d_e
2 NaN
3 f_g_h
Name: A, dtype: object
d['A'].str.join("!")
0 a!_!b!_!c
1 c!_!d!_!e
2 NaN
3 f!_!g!_!h
Name: A, dtype: object
d['A'].str.contains('d')
0 False
1 True
2 NaN
3 False
Name: A, dtype: object
d.fillna('0')[d.fillna('0')['A'].str.contains('d')]
A | |
---|---|
1 | c_d_e |
d.fillna('0')[d['A'].fillna('0').str.contains('d|e')]
#表示或的關(guān)系用"A|B",表示且用'A.*B|B.*A'
A | |
---|---|
1 | c_d_e |
d['A'].str.replace("_", ".")
0 a.b.c
1 c.d.e
2 NaN
3 f.g.h
Name: A, dtype: object
d['A'].str.repeat(3)
0 a_b_ca_b_ca_b_c
1 c_d_ec_d_ec_d_e
2 NaN
3 f_g_hf_g_hf_g_h
Name: A, dtype: object
d['A'].str.pad(10, fillchar="0")
0 00000a_b_c
1 00000c_d_e
2 NaN
3 00000f_g_h
Name: A, dtype: object
d['A'].str.pad(10, side="right", fillchar="?")
0 a_b_c?????
1 c_d_e?????
2 NaN
3 f_g_h?????
Name: A, dtype: object
d['A'].str.center(10, fillchar="?")
0 ??a_b_c???
1 ??c_d_e???
2 NaN
3 ??f_g_h???
Name: A, dtype: object
d['A'].str.ljust(10, fillchar="?")
0 a_b_c?????
1 c_d_e?????
2 NaN
3 f_g_h?????
Name: A, dtype: object
d['A'].str.rjust(10, fillchar="?")
0 ?????a_b_c
1 ?????c_d_e
2 NaN
3 ?????f_g_h
Name: A, dtype: object
d['A'].str.zfill(10)
0 00000a_b_c
1 00000c_d_e
2 NaN
3 00000f_g_h
Name: A, dtype: object
d['A'].str.wrap(3)
0 a_bn_c
1 c_dn_e
2 NaN
3 f_gn_h
Name: A, dtype: object
d['A'].str.slice(1,3)
0 _b
1 _d
2 NaN
3 _g
Name: A, dtype: object
d['A'].str.slice_replace(1, 3, "?")
0 a?_c
1 c?_e
2 NaN
3 f?_h
Name: A, dtype: object
d['A'].str.count("b")
0 1.0
1 0.0
2 NaN
3 0.0
Name: A, dtype: float64
d['A'].str.startswith("a")
0 True
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.endswith("e")
0 False
1 True
2 NaN
3 False
Name: A, dtype: object
d['A'].str.findall("[a-z]")
0 [a, b, c]
1 [c, d, e]
2 NaN
3 [f, g, h]
Name: A, dtype: object
d['A'].str.match("[d-z]")
0 False
1 False
2 NaN
3 True
Name: A, dtype: object
d['A'].str.extract("([d-z])")
0 | |
---|---|
0 | NaN |
1 | d |
2 | NaN |
3 | f |
d['A'].str.len()
0 5.0
1 5.0
2 NaN
3 5.0
Name: A, dtype: float64
df = pd.DataFrame(['a_b ', ' d_e ', np.nan, 'f_g '],columns = ['B'])
df['B']
0 a_b
1 d_e
2 NaN
3 f_g
Name: B, dtype: object
df['B'].str.strip()
0 a_b
1 d_e
2 NaN
3 f_g
Name: B, dtype: object
df['B'].str.rstrip()
0 a_b
1 d_e
2 NaN
3 f_g
Name: B, dtype: object
df['B'].str.lstrip()
0 a_b
1 d_e
2 NaN
3 f_g
Name: B, dtype: object
d['A'] .str.partition('_')
0 | 1 | 2 | |
---|---|---|---|
0 | a | _ | b_c |
1 | c | _ | d_e |
2 | NaN | NaN | NaN |
3 | f | _ | g_h |
d['A'].str.rpartition('_')
0 | 1 | 2 | |
---|---|---|---|
0 | a_b | _ | c |
1 | c_d | _ | e |
2 | NaN | NaN | NaN |
3 | f_g | _ | h |
d['A'].str.lower()
0 a_b_c
1 c_d_e
2 NaN
3 f_g_h
Name: A, dtype: object
d['A'].str.upper()
0 A_B_C
1 C_D_E
2 NaN
3 F_G_H
Name: A, dtype: object
d['A'].str.find('d')
0 -1.0
1 2.0
2 NaN
3 -1.0
Name: A, dtype: float64
d['A'].str.rfind('d')
0 -1.0
1 2.0
2 NaN
3 -1.0
Name: A, dtype: float64
d['A'].str.index('_')
0 1.0
1 1.0
2 NaN
3 1.0
Name: A, dtype: float64
d['A'].str.rindex('_')
0 3.0
1 3.0
2 NaN
3 3.0
Name: A, dtype: float64
d['A'].str.capitalize()
0 A_b_c
1 C_d_e
2 NaN
3 F_g_h
Name: A, dtype: object
d['A'].str.capitalize()
0 A_b_c
1 C_d_e
2 NaN
3 F_g_h
Name: A, dtype: object
d['A'].str.isalnum()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.isalpha()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.isdigit()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.isspace()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.islower()
0 True
1 True
2 NaN
3 True
Name: A, dtype: object
d['A'].str.isupper()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.istitle()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.isnumeric()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
d['A'].str.isdecimal()
0 False
1 False
2 NaN
3 False
Name: A, dtype: object
數(shù)據(jù)分析咨詢請掃描二維碼
若不方便掃碼,搜微信號:CDAshujufenxi
LSTM 模型輸入長度選擇技巧:提升序列建模效能的關(guān)鍵? 在循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)家族中,長短期記憶網(wǎng)絡(luò)(LSTM)憑借其解決長序列 ...
2025-07-11CDA 數(shù)據(jù)分析師報(bào)考條件詳解與準(zhǔn)備指南? ? 在數(shù)據(jù)驅(qū)動決策的時(shí)代浪潮下,CDA 數(shù)據(jù)分析師認(rèn)證愈發(fā)受到矚目,成為眾多有志投身數(shù) ...
2025-07-11數(shù)據(jù)透視表中兩列相乘合計(jì)的實(shí)用指南? 在數(shù)據(jù)分析的日常工作中,數(shù)據(jù)透視表憑借其強(qiáng)大的數(shù)據(jù)匯總和分析功能,成為了 Excel 用戶 ...
2025-07-11尊敬的考生: 您好! 我們誠摯通知您,CDA Level I和 Level II考試大綱將于 2025年7月25日 實(shí)施重大更新。 此次更新旨在確保認(rèn) ...
2025-07-10BI 大數(shù)據(jù)分析師:連接數(shù)據(jù)與業(yè)務(wù)的價(jià)值轉(zhuǎn)化者? ? 在大數(shù)據(jù)與商業(yè)智能(Business Intelligence,簡稱 BI)深度融合的時(shí)代,BI ...
2025-07-10SQL 在預(yù)測分析中的應(yīng)用:從數(shù)據(jù)查詢到趨勢預(yù)判? ? 在數(shù)據(jù)驅(qū)動決策的時(shí)代,預(yù)測分析作為挖掘數(shù)據(jù)潛在價(jià)值的核心手段,正被廣泛 ...
2025-07-10數(shù)據(jù)查詢結(jié)束后:分析師的收尾工作與價(jià)值深化? ? 在數(shù)據(jù)分析的全流程中,“query end”(查詢結(jié)束)并非工作的終點(diǎn),而是將數(shù) ...
2025-07-10CDA 數(shù)據(jù)分析師考試:從報(bào)考到取證的全攻略? 在數(shù)字經(jīng)濟(jì)蓬勃發(fā)展的今天,數(shù)據(jù)分析師已成為各行業(yè)爭搶的核心人才,而 CDA(Certi ...
2025-07-09【CDA干貨】單樣本趨勢性檢驗(yàn):捕捉數(shù)據(jù)背后的時(shí)間軌跡? 在數(shù)據(jù)分析的版圖中,單樣本趨勢性檢驗(yàn)如同一位耐心的偵探,專注于從單 ...
2025-07-09year_month數(shù)據(jù)類型:時(shí)間維度的精準(zhǔn)切片? ? 在數(shù)據(jù)的世界里,時(shí)間是最不可或缺的維度之一,而year_month數(shù)據(jù)類型就像一把精準(zhǔn) ...
2025-07-09CDA 備考干貨:Python 在數(shù)據(jù)分析中的核心應(yīng)用與實(shí)戰(zhàn)技巧? ? 在 CDA 數(shù)據(jù)分析師認(rèn)證考試中,Python 作為數(shù)據(jù)處理與分析的核心 ...
2025-07-08SPSS 中的 Mann-Kendall 檢驗(yàn):數(shù)據(jù)趨勢與突變分析的有力工具? ? ? 在數(shù)據(jù)分析的廣袤領(lǐng)域中,準(zhǔn)確捕捉數(shù)據(jù)的趨勢變化以及識別 ...
2025-07-08備戰(zhàn) CDA 數(shù)據(jù)分析師考試:需要多久?如何規(guī)劃? CDA(Certified Data Analyst)數(shù)據(jù)分析師認(rèn)證作為國內(nèi)權(quán)威的數(shù)據(jù)分析能力認(rèn)證 ...
2025-07-08LSTM 輸出不確定的成因、影響與應(yīng)對策略? 長短期記憶網(wǎng)絡(luò)(LSTM)作為循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)的一種變體,憑借獨(dú)特的門控機(jī)制,在 ...
2025-07-07統(tǒng)計(jì)學(xué)方法在市場調(diào)研數(shù)據(jù)中的深度應(yīng)用? 市場調(diào)研是企業(yè)洞察市場動態(tài)、了解消費(fèi)者需求的重要途徑,而統(tǒng)計(jì)學(xué)方法則是市場調(diào)研數(shù) ...
2025-07-07CDA數(shù)據(jù)分析師證書考試全攻略? 在數(shù)字化浪潮席卷全球的當(dāng)下,數(shù)據(jù)已成為企業(yè)決策、行業(yè)發(fā)展的核心驅(qū)動力,數(shù)據(jù)分析師也因此成為 ...
2025-07-07剖析 CDA 數(shù)據(jù)分析師考試題型:解鎖高效備考與答題策略? CDA(Certified Data Analyst)數(shù)據(jù)分析師考試作為衡量數(shù)據(jù)專業(yè)能力的 ...
2025-07-04SQL Server 字符串截取轉(zhuǎn)日期:解鎖數(shù)據(jù)處理的關(guān)鍵技能? 在數(shù)據(jù)處理與分析工作中,數(shù)據(jù)格式的規(guī)范性是保證后續(xù)分析準(zhǔn)確性的基礎(chǔ) ...
2025-07-04CDA 數(shù)據(jù)分析師視角:從數(shù)據(jù)迷霧中探尋商業(yè)真相? 在數(shù)字化浪潮席卷全球的今天,數(shù)據(jù)已成為企業(yè)決策的核心驅(qū)動力,CDA(Certifie ...
2025-07-04CDA 數(shù)據(jù)分析師:開啟數(shù)據(jù)職業(yè)發(fā)展新征程? ? 在數(shù)據(jù)成為核心生產(chǎn)要素的今天,數(shù)據(jù)分析師的職業(yè)價(jià)值愈發(fā)凸顯。CDA(Certified D ...
2025-07-03