小编ggu*_*pta的帖子

在python中解析具有多个根元素的xml文件

我有一个xml文件,我需要从文件中获取一些标记以供某些使用,其数据如下:

<?xml version="1.0"?>
<data>
    <country name="Liechtenstein">
        <rank>1</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria" direction="E"/>
        <neighbor name="Switzerland" direction="W"/>
    </country>
    <country name="Singapore">
        <rank>4</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia" direction="N"/>
    </country>
    <country name="Panama">
        <rank>68</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>
<?xml version="1.0"?>
<data>
    <country name="Liechtenstein1">
        <rank>1</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria1" direction="E"/>
        <neighbor name="Switzerland1" direction="W"/>
    </country>
    <country name="Singapore">
        <rank>4</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia1" direction="N"/>
    </country>
    <country name="Panama">
        <rank>68</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>
Run Code Online (Sandbox Code Playgroud)

我需要解析这个,所以我用了:

import xml.etree.ElementTree …
Run Code Online (Sandbox Code Playgroud)

python xml parsing python-2.7

6
推荐指数
2
解决办法
3928
查看次数

绘制两个 Pandas 数据框列之间的差异分布

我有一个熊猫数据框,它有列A&B

我只想绘制列A&之间差异百分比的分布图B

        A                B
  1 1.051990e+10    1.051990e+04
  2 1.051990e+10    1.051990e+04
  5 4.841800e+10    1.200000e+10
  8 2.327700e+10    2.716000e+10
  9 1.204900e+10    2.100000e+08
Run Code Online (Sandbox Code Playgroud)

分布图就像,有多少条记录有 10% 的差异,有多少条记录有 20% 的差异

我试过如下

df percCal(x,y):
  return (x-y)*100/x

df['perc'] = df.apply(lambda x: percCal(df['A'], df['B']), axis=1)
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为我是新手,请帮忙

python plot distribution pandas

1
推荐指数
1
解决办法
1727
查看次数

标签 统计

python ×2

distribution ×1

pandas ×1

parsing ×1

plot ×1

python-2.7 ×1

xml ×1