-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeginnings.py
35 lines (25 loc) · 850 Bytes
/
beginnings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pandas as pd
# Create a dictionary
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Oscar'],
'Age': [25, 30, 35, 40, 51],
'City': ['New York', 'Los Angeles', 'Houston', 'Houston', 'Madrid']
}
# Convert the dictionary into a DataFrame
df = pd.DataFrame(data)
# Display the DataFrame
# print(df)
# print(df.sort_values(by='Age'))
# print(df.describe())
print(df.groupby('City')['Age'].mean())
grouped_data = df.groupby(['City']).size()
print(grouped_data)
# Group by 'City' and calculate multiple statistics for the 'Age' column
grouped_stats = df.groupby('City')['Age'].agg(['mean', 'min', 'max', 'count'])
print(grouped_stats)
# Iterate over each group
# for city, group in df.groupby('City'):
# print(f"City: {city}")
# print(group)
pi = -33333.14159
print(f"Pi rounded to 2 decimal places is {pi:+,.2f}")