Questions
Questions
Use the str accessor for string operations, such as str.contains() to check for specific words and assign specific values to new columns based on these conditions. str.slice() can extract specific parts of strings, like the first few characters .
Use the isnull() method to identify missing data and the sum() method to count them across each column. Calculate the percentage of missing data per column by dividing this sum by the total number of rows and then multiplying by 100 .
Use the corr() method to generate a correlation matrix for numeric columns. To interpret the correlation between two columns, look at the matrix's intersection values, which show correlation coefficients (ranging from -1 to 1).
Use the value_counts() method on a DataFrame column to compute the frequency of each unique response. Sorting the results can help identify the most and least common entries in descending order .
First, load the dataset using pandas’ read_csv() function. To inspect the DataFrame's basic information, use the head() method to view the first few rows, followed by the info() method to get a summary of the DataFrame. This includes the number of non-null values and data types of each column .
Use the duplicated() method to identify duplicate rows. To remove them, use drop_duplicates(), creating a new DataFrame without duplicates. Confirm the changes by checking the row count before and after removal .
Use the to_datetime() function to convert dates to pandas datetime format. For numerical data, use astype() to ensure conversion to integer format. These transformations maintain consistency and allow for accurate calculations .
To filter rows, use conditional indexing. For example, select rows where a column value is greater than a threshold. Then use double brackets with column names to extract specific columns, creating a subset DataFrame .
Use the groupby() function to group data by a specified column. Apply aggregate functions such as sum() for total and mean() for average on the grouped data column. Sort results using the sort_values() method for better readability .
Calculate the range of ages by subtracting the minimum value from the maximum value using the min() and max() functions on the age column: max(age) - min(age).