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

目录

一、实战场景

二、主要知识点

文件读写

基础语法

Pandas

list

三、菜鸟实战

1、创建 python 文件

2、运行结果 


一、实战场景

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

二、主要知识点

  • 文件读写

  • 基础语法

  • Pandas

  • list

三、菜鸟实战

马上安排!

1、创建 python 文件

import pandas as pd

df = 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']

  菜鸟实战,持续学习!  

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸟实战

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值