0% found this document useful (0 votes)
22 views9 pages

Class 12 IP Practical Answers Programmer Style

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Class 12 IP Practical Answers Programmer Style

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

#1. Create a pandas series from a dictionary of values and an ndarray.

#2. Given a Series, print all the elements that are above the 75th percentile.

#3. Create a DataFrame quarterly sales where each row contains the item category,

item name, and expenditure. Group the rows by the category, and print the total expenditure per

category.
#1. Answer:

```python

import pandas as pd

import numpy as np

# Creating a pandas series from dictionary and ndarray

data_dict = {'a': 10, 'b': 20, 'c': 30}

data_ndarray = np.array([1, 2, 3])

series_from_dict = pd.Series(data_dict)

series_from_ndarray = pd.Series(data_ndarray)

print(series_from_dict)

print(series_from_ndarray)

```

#2. Answer:

```python

# Find elements above the 75th percentile

series = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9])

percentile_75 = series.quantile(0.75)

print(series[series > percentile_75])

```

#3. Answer:

```python

# Creating a DataFrame for quarterly sales


data = {'Category': ['Electronics', 'Clothing', 'Electronics', 'Clothing'],

'Item': ['TV', 'Shirt', 'Phone', 'Jeans'],

'Expenditure': [300, 50, 200, 40]}

df = pd.DataFrame(data)

grouped = df.groupby('Category')['Expenditure'].sum()

print(grouped)

```

You might also like