<jupyter_start><jupyter_text>parse xml<jupyter_code>attrib_keys = ['Id', 'UserId']
    ret_node_attribs_dict = {'Id': '1', 'UserId': '2'}
    xml = '<badges><row Id="1" UserId="2" Name="Autobiographer" Date="2010-07-07T19:08:45.757" Class="3" TagBased="False" /></badges>'
    from xml.etree import ElementTree as et
    root = et.fromstring(xml)
    

    
root.get('Id')
for i, n in enumerate(root): 
    print(i,n)
    
root[0]
print(root.attrib)
from helpers import *
node_attribs_dict = raw.parse_one_node(root[0], attrib_keys)
node_attribs_dict == ret_node_attribs_dict
ret_node_attribs_dict
node_attribs_dict<jupyter_output><empty_output><jupyter_text>get attribs from xml<jupyter_code>attrib_keys = ['Id', 'UserId']
xml = '<badges>'\
    '<row Id="1" UserId="2" Name="Autobiographer" '\
    'Date="2010-07-07T19:08:45.757" Class="3" TagBased="False" />'\
    '<row Id="2" UserId="2" Name="User2" '\
    'Date="2010-07-08T20:00:15.000" Class="4" TagBased="True" />'\
    '</badges>'

from xml.etree import ElementTree as et
root = et.fromstring(xml)

from helpers import raw
ret = raw.parse_root(root, attrib_keys)

print(ret)<jupyter_output>process 1 items
2
[{'Id': '1', 'UserId': '2'}, {'Id': '2', 'UserId': '2'}]<jupyter_text>csv module<jupyter_code>import csv
csv.QUOTE_ALL
csv.QUOTE_MINIMAL
text = ''
import urllib
rich_text_fields = {'Body','Title','AboutMe','Text','Comment'}
key = 'Text'
value = 'asdasd sa\n asdsasad \n\r asdjskladjsda \t \"asdsadsa\"'
if key in rich_text_fields:
    print('url encoding')
    value = urllib.parse.quote(value)
print(value)
v = urllib.parse.unquote(value)
print(v)<jupyter_output>asdasd sa
 asdsasad 
 asdjskladjsda 	 "asdsadsa"<jupyter_text>regex to unpack tags<jupyter_code>import re

str1 = '<distributions><normality-assumption>'
pattern = '\<([^\>]*)\>'
tags1  = re.findall(pattern=pattern, string=str1)
tags2 = ','.join(re.findall(pattern=pattern, string=str1))
tags1
','.join(e for e in tags1)
tags2
import pandas as pd
df = pd.DataFrame({'a': ['1'], 'b': ['<distributions><normality-assumption>']})
df
df['c'] = df['b'].apply(lambda b: ','.join(re.findall(pattern = pattern, string = str(b))))
df<jupyter_output><empty_output><jupyter_text>pandas data range shift<jupyter_code>import pandas as pd  

df = pd.DataFrame({'month':pd.date_range('20200101', periods=8, freq='M'),
'x': [1,2,3,3,2,5,4,3],
'y': [2,1,2,3,3,2,5,4]} )

df['month'] = df['month'].dt.strftime('%b')
print(df)

df['y'] =df.y.shift(periods=-2, fill_value=0)

print(df)<jupyter_output>month  x  y
0   Jan  1  2
1   Feb  2  1
2   Mar  3  2
3   Apr  3  3
4   May  2  3
5   Jun  5  2
6   Jul  4  5
7   Aug  3  4
  month  x  y
0   Jan  1  2
1   Feb  2  3
2   Mar  3  3
3   Apr  3  2
4   May  2  5
5   Jun  5  4
6   Jul  4  0
7   Aug  3  0<jupyter_text>decompose datas et<jupyter_code>import pandas as pd
df1 = pd.read_csv('3mj\decomposed_3mj.csv')
print(df1.query('iteration == 175'))<jupyter_output>Unnamed: 0  average_degree  betweeness  edges  \
176         176        0.570439    0.000035  494.0   

                              filename  iteration  no_connected_components  \
176  3mj/subgraph-175-game-center.gexf      175.0                    448.0   

     nodes          tag  
176  866.0  game-center
{'fraction_non_alphanumeric': 0.1620785648004949, 'fraction_numerical': 0.06464583977729663, 'mean_word_length': 3.9, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '208594', 'license': 'MIT', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1346, 'n_words': 287, 'path': '99-misc.ipynb', 'repo_name': 'mutazag/godzilla-sina', 'size': '3233'}