> 文档中心 > 【Python 实战基础】Pandas如何从字符串中解析某一数据,并统计多于一次的该数据

【Python 实战基础】Pandas如何从字符串中解析某一数据,并统计多于一次的该数据

目录

一、实战场景

二、主要知识点

文件读写

基础语法

Pandas

list

三、菜鸟实战

1、创建 python 文件

2、运行结果 


一、实战场景

实战场景:Pandas如何从字符串中解析某一数据,并统计多于一次的该数据

二、主要知识点

  • 文件读写

  • 基础语法

  • Pandas

  • list

三、菜鸟实战

马上安排!

1、创建 python 文件

import pandas as pddf = pd.read_json('market.json')# profile形如:^AEX (Holandia)#遍历df['country'] = df['profile'].map(  lambda x: x.split("(")[1].split(")")[0])print(df.head(5))df_counts = df["country"].value_counts()print(df_counts)print(list(df_counts[df_counts > 1].index))

2、运行结果 

           profile   time     price  change pct_change  reference_price      open       low      high   country
0  ^AEX (Holandia)  14:12    548.73    7.95   (+1.47%)           540.78    546.55    544.72    550.72  Holandia
1   ^ATX (Austria)  14:11   2147.90   17.68   (+0.83%)          2130.22   2131.47   2118.71   2163.92   Austria
2   ^ATXC (Grecja)  14:13    621.82   -2.80   (-0.45%)           624.62    627.48    621.82    631.70    Grecja
3  ^BEL20 (Belgia)  14:11   3251.39   30.51   (+0.95%)          3220.88   3252.21   3228.77   3266.11    Belgia
4     ^BUX (Węgry)  14:12  32831.01  534.27   (+1.65%)         32296.74  32421.05  32421.05  32865.43     Węgry
Rosja              2
Wielka Brytania    2
Holandia           1
Finlandia          1
Turcja             1
Szwajcaria         1
Czechy             1
Portugalia         1
Norwegia           1
Szwecja            1
Dania              1
Austria            1
Hiszpania          1
Włochy             1
Niemcy             1
Francja            1
Węgry              1
Belgia             1
Grecja             1
Polska             1
Name: country, dtype: int64
['Rosja', 'Wielka Brytania']

  菜鸟实战,持续学习!