Feb-24-2019, 11:46 AM
(This post was last modified: Feb-24-2019, 11:47 AM by erdem_ustunmu.)
Hello;
Thank you very much for your help and your efforts.
I started doing something with your solutions and examples.
Trying to adapt slowly to your example
1-is it possible to write text of type for sumstat
# All sumStat
>>> [i.text.strip() for i in var.find_all('sumStat')]
as below or otherwise
['vald':'76208', 'invd':'0', 'min':'1001', 'max':'1800', 'mean':'1412.79', 'stdev':'231.955']
2.How do I combine category tags?
['1-Eastern','freq':'16926'] | ['2-Central','freq':'31316'] | ['3-Western','freq':'13527'] |......
I would like your help.
Best regards
Thank you very much for your help and your efforts.
I started doing something with your solutions and examples.
Trying to adapt slowly to your example
from bs4 import BeautifulSoup lst = [] soup = BeautifulSoup(open('NPL_2008_LFS_v01_M_v01_A_ILOVAR.xml', encoding='utf-8'), 'xml') title = soup.find('titl') producer = soup.find('producer') print(title.text.strip()) print(producer.attrs.get('affiliation')) data = soup.find('dataDscr') vars = data.find_all('var') for var in vars: ID=var.attrs.get('ID') name=var.attrs.get('name') files=var.attrs.get('files') dcml=var.attrs.get('dcml') intrvl=var.attrs.get('intrvl') labl=var.find('labl').text.strip() sumStat=[i.text.strip() for i in var.find_all('sumStat')] print(title.text.strip(),producer.text.strip(),ID,name,files,dcml,intrvl,labl,sumStat) lst.append((title.text.strip(),producer.text.strip(),ID,name,files,dcml,intrvl,labl,sumStat))I couldn't do it even though I tried a lot.So I want to ask 2 things here.
1-is it possible to write text of type for sumstat
# All sumStat
>>> [i.text.strip() for i in var.find_all('sumStat')]
as below or otherwise
['vald':'76208', 'invd':'0', 'min':'1001', 'max':'1800', 'mean':'1412.79', 'stdev':'231.955']
2.How do I combine category tags?
<catgry> <catValu> 1 </catValu> <labl> Eastern </labl> <catStat type="freq"> 16926 </catStat> </catgry> <catgry> <catValu> 2 </catValu> <labl> Central </labl> <catStat type="freq"> 31316 </catStat> </catgry> <catgry> <catValu> 3 </catValu> <labl> Western </labl> <catStat type="freq"> 13527 </catStat> </catgry> <catgry> <catValu> 4 </catValu> <labl> Mid-Western </labl> <catStat type="freq"> 8060 </catStat> </catgry> <catgry> <catValu> 5 </catValu> <labl> Far-Western </labl> <catStat type="freq"> 6379 </catStat> </catgry>Like the example below
['1-Eastern','freq':'16926'] | ['2-Central','freq':'31316'] | ['3-Western','freq':'13527'] |......
I would like your help.
Best regards