NumPy and Data Visualization Tasks
NumPy and Data Visualization Tasks
To create a NumPy array of random integers between 10 and 100 with shape (5, 5), use 'np.random.randint(10, 100, (5, 5))'. Replace even numbers with -1 using 'array[array % 2 == 0] = -1'. Normalize the array by applying '(array - array.min()) / (array.max() - array.min())' to scale values between 0 and 1 .
Use a bar chart with 'plt.bar(departments, employee_counts)' for visualizing employee numbers, ensuring clarity with labels. For a pie chart, 'plt.pie(employee_percentages, labels=departments)' efficiently shows the division of employees across departments .
Create a DataFrame using 'pd.DataFrame()' with specified columns. Add a Bonus column as 'df['Bonus'] = df['Salary'] * 0.1'. Filter with 'df[df['Salary'] > 50000]'. Sort by Salary in descending order using 'df.sort_values(by='Salary', ascending=False)' .
Use 'plt.plot(months, revenue)' for the line plot, adding labels with 'plt.xlabel()' and 'plt.ylabel()', a title with 'plt.title()', and legend with 'plt.legend()'. Highlight maximum revenue using 'plt.annotate()' to point out the specific month .
Group by Department using 'df.groupby('Department')['Salary'].mean()' for average salary. Identify the highest with 'df_department.agg(max)'. Use Matplotlib for plots: bar chart via 'plt.bar()', and pie chart with 'plt.pie()' to show distributions .
First, generate the array using 'np.random.random(100)'. Compute the mean with 'np.mean(array)', median with 'np.median(array)', variance with 'np.var(array)', and standard deviation with 'np.std(array)'. For values below 0.2, replace them with the mean using 'array[array < 0.2] = np.mean(array)' .
Replace even numbers with 'array[array % 2 == 0] = -1'. Normalize using the formula '(array - array.min()) / (array.max() - array.min())' ensuring values range from 0 to 1. This process transforms and adequately scales the array .
Create a DataFrame with columns 'Day', 'Temperature', 'Humidity'. Find the highest temperature with 'df.loc[df['Temperature'].idxmax()]'. Compute average temperature and humidity using 'df.mean()' on respective columns. .
Histograms are plotted with 'plt.hist(scores)' for each subject, revealing score distribution. For correlation, use 'plt.scatter(math_scores, science_scores)' and add a trendline with 'plt.plot(polyfit, linestyle)'. This aids in visualizing relationships between subjects .
Create matrices using 'np.random.randint(...)' for each. Use '+', '-', and '@' for addition, subtraction, and multiplication respectively. Compute the determinant with 'np.linalg.det(matrix)' and inverse with 'np.linalg.inv(matrix)', provided the determinant is non-zero .