Skip to content

Commit 549787c

Browse files
committed
asyncio added
1 parent f305ade commit 549787c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

manage_attributes.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Manage Class Attributes with @property Decorator
2+
class Product:
3+
def __init__(self, name, price):
4+
self.name = name
5+
self._price = price
6+
@property
7+
def price(self):
8+
return self._price
9+
10+
@price.setter
11+
def price(self, value):
12+
if isinstance(value, (int, float)):
13+
raise ValueError("Price must be a number")
14+
if value < 0:
15+
raise ValueError("Price cannot be negative")
16+
17+
18+
# creating instance of the class
19+
product = Product("Laptop", 300)
20+
print(product.price)

pd_to_xml.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Transforming Pandas DataFrame to XML
2+
import pandas as pd
3+
4+
data ={
5+
'Name': ['asibeh', 'alice', 'tenager'],
6+
'age': [23, 40, 34],
7+
'city':['addis ababa', 'bahirdar', 'db']
8+
}
9+
df = pd.DataFrame(data)
10+
print(df)
11+
12+
13+
import xml.etree.ElementTree as ET
14+
15+
def df_to_xml(df, root_name, row_name):
16+
root = ET.Element(root_name)
17+
for _, row in df.iterrows():
18+
item = ET.SubElement(root, row_name)
19+
for col_name, col_value in row.items():
20+
sub_item = ET.SubElement(item, col_name)
21+
sub_item.text = str(col_value)
22+
return ET.tostring(root, encoding='unicode')
23+
24+
xml_data = df_to_xml(df, 'Data', 'Person')
25+
print(xml_data)

0 commit comments

Comments
 (0)