<jupyter_start><jupyter_text>**1. Create a DataFrame birds from this dictionary data which has the index labels.**<jupyter_code>df = pd.DataFrame(data , index=labels)
df<jupyter_output><empty_output><jupyter_text>**2. Display a summary of the basic information about birds DataFrame and its data.**<jupyter_code>df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Index: 10 entries, a to j
Data columns (total 4 columns):
birds       10 non-null object
age         8 non-null float64
visits      10 non-null int64
priority    10 non-null object
dtypes: float64(1), int64(1), object(2)
memory usage: 400.0+ bytes<jupyter_text>**3. Print the first 2 rows of the birds dataframe.**<jupyter_code>df.head(2)<jupyter_output><empty_output><jupyter_text>**4. Print all the rows with only 'birds' and 'age' columns from the dataframe**<jupyter_code>df[['birds', 'age']]<jupyter_output><empty_output><jupyter_text>**5. select [2, 3, 7] rows and in columns ['birds', 'age', 'visits']**<jupyter_code>df.iloc[[2,3,7], [1,2,3]]<jupyter_output><empty_output><jupyter_text>**6. select the rows where the number of visits is less than 4**<jupyter_code>df[df['visits'] < 4]<jupyter_output><empty_output><jupyter_text>**7. select the rows with columns ['birds', 'visits'] where the age is missing i.e NaN**<jupyter_code>df.loc[df['age'].isnull(), ['birds', 'visits']]<jupyter_output><empty_output><jupyter_text>**8. Select the rows where the birds is a Cranes and the age is less than 4**<jupyter_code>df[(df['birds'] == 'Cranes') & (df['age'] < 4)]<jupyter_output><empty_output><jupyter_text>**9. Select the rows the age is between 2 and 4(inclusive)**<jupyter_code>df[(df['age'] > 2) & (df['age'] <= 4)]<jupyter_output><empty_output><jupyter_text>**10. Find the total number of visits of the bird Cranes**<jupyter_code>df.loc[(df['birds'] == 'Cranes'), ['visits']].sum()<jupyter_output><empty_output><jupyter_text>**11. Calculate the mean age for each different birds in dataframe.**<jupyter_code>df['age'].mean() # mean for all birds.
df.groupby('birds')['age'].mean() # mean for different birds.<jupyter_output><empty_output><jupyter_text>**12. Append a new row 'k' to dataframe with your choice of values for each column. Then delete that row to return the original DataFrame.**<jupyter_code>df.loc['k'] = ['Blue Bird', 1.2, 10, 'no']
df
df = df.drop('k')
df<jupyter_output><empty_output><jupyter_text>**13. Find the number of each type of birds in dataframe (Counts)**<jupyter_code>df.groupby(['birds']).count()<jupyter_output><empty_output><jupyter_text>**14. Sort dataframe (birds) first by the values in the 'age' in decending order, then by the value in the 'visits' column in ascending order.**<jupyter_code>print(df.sort_values('age', ascending=False))
print(" ")
print(df.sort_values('visits', ascending=True))<jupyter_output>birds  age  visits priority
i  spoonbills  8.0       3       no
e  spoonbills  6.0       3       no
g     plovers  5.5       2       no
b      Cranes  4.0       4      yes
j  spoonbills  4.0       2       no
a      Cranes  3.5       2      yes
f      Cranes  3.0       4       no
c     plovers  1.5       3       no
d  spoonbills  NaN       4      yes
h      Cranes  NaN       2      yes
 
        birds  age  visits priority
a      Cranes  3.5       2      yes
g     plovers  5.5       2       no
h      Cranes  NaN       2      yes
j  spoonbills  4.0       2       no
c     plovers  1.5       3       no
e  spoonbills  6.0       3       no
i  spoonbills  8.0       3       no
b      Cranes  4.0       4      yes
d  spoonbills  NaN       4      yes
f      Cranes  3.0       4       no<jupyter_text>**15. Replace the priority column values with'yes' should be 1 and 'no' should be 0**<jupyter_code>df['priority'] = df['priority'].map(dict(yes=1, no=0)) # It will update original data frame.
# df.priority = df.priority.map({'yes': 1, 'no': 0}) # Same as above It will update original data frame.
#df.priority.map({'yes': 1, 'no': 0}) # It will update at run time only.
df<jupyter_output><empty_output><jupyter_text>**16. In the 'birds' column, change the 'Cranes' entries to 'trumpeters'.**<jupyter_code># df['birds'] = df['birds'].map(lambda b: 'trumpeters' if b=='Cranes' else b) # one other method to replace
df = df.replace('Cranes', 'trumpeters')
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13557358053302435, 'fraction_numerical': 0.030359212050984935, 'mean_word_length': 3.779623477297896, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '562401', 'license': 'MIT', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1552, 'n_words': 447, 'path': 'Assigment2/pandas_basics_practice.ipynb', 'repo_name': 'ashwini1502/AppliedAI', 'size': '4315'}