Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

python - Split value in pandas dataframe


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use Series.str.split:

In [1908]: df['Symbol'] = df['Stock'].str.split('.').str[0]

In [1909]: df
Out[1909]: 
       Stock   ROC5  ROC20  ROC63  ROCmean  Symbol
0    IBGL.SW  -0.59   3.55   6.57     3.18    IBGL
0    EHYA.SW   0.98   4.00   6.98     3.99    EHYA
0    HIGH.SW   0.94   4.22   7.18     4.11    HIGH
0    IHYG.SW   0.56   2.46   6.16     3.06    IHYG
0    HYGU.SW   1.12   4.56   7.82     4.50    HYGU
0    IBCI.SW   0.64   3.57   6.04     3.42    IBCI
0    IAEX.SW   8.34  18.49  14.95    13.93    IAEX
0    AGED.SW   9.45  24.74  28.13    20.77    AGED
0    ISAG.SW   7.97  21.61  34.34    21.31    ISAG
0    IAPD.SW   0.51   6.62  19.54     8.89    IAPD
0    IASP.SW   1.08   2.54  12.18     5.27    IASP
0    RBOT.SW  10.35  30.53  39.15    26.68    RBOT
0    RBOD.SW  11.33  30.50  39.69    27.17    RBOD
0    BRIC.SW   7.24  11.08  75.60    31.31    BRIC
0    CNYB.SW   1.14   4.78   8.36     4.76    CNYB
0     FXC.SW   5.68  13.84  19.29    12.94     FXC
0   DJSXE.SW   3.11   9.24   6.44     6.26   DJSXE
0  CSSX5E.SW  -0.53   5.29  11.85     5.54  CSSX5E

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...