Py-06: EDA Techniques: Correlation Analysis, Handling Missing Data, and Grouped Summaries in Python
#Installing_Libraries
!pip install pandas matplotlib seaborn plotly pyreadstat
#Importing_Libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import pyreadstat # For reading SPSS files
#Loading_and_Exploring_the_Data
Load SPSS data
file_path = "path_to_your_file/exam_data.sav" # Replace with your actual file path
data_set, meta = pyreadstat.read_sav(file_path)
data_set = pd.DataFrame(data_set) # Convert to DataFrame
Display the first few rows and get data information
print(data_set.head())
print(data_set.info())
#Correlation_Analysis
Select relevant numerical columns
numerical_cols = ['Age', 'Charges', 'BMI'] # Replace with actual column names
cor_matrix = data_set[numerical_cols].corr()
Plot the correlation heatmap
plt.figure(figsize=(8, 6))
sns.heatmap(cor_matrix, annot=True, cmap='coolwarm', square=True)
plt.title("Correlation Matrix of Numerical Features")
plt.show()
#Handling_Missing_Data
Option 1: Drop rows with any missing values
data_cleaned = data_set.dropna()
print("Data after dropping missing values:")
print(data_cleaned.info())
Option 2: Fill missing values with the median
data_filled = data_set.fillna(data_set.median())
print("Data after filling missing values with median:")
print(data_filled.info())
#Grouped_Summary_Statistics
Calculate the average charges based on smoker status
grouped_data = data_set.groupby('Smoker')['Charges'].mean() # Replace 'Smoker' and 'Charges' with actual column names
print("Average Charges by Smoking Status:")
print(grouped_data)
#PythonSeries
#LearnPython
#PythonForBeginners
#PythonTutorial
#CodingWithPython
#PythonBasics
#PythonProgramming
#PythonLearning
#PythonCode
#PythonForEveryone
#Python101
#PythonDevelopers
#PythonScripting
#PythonTips
#PythonJourney
Nesta página do site você pode assistir ao vídeo on-line 06: Python : EDA Techniques: Correlation Analysis, Handling Missing Data, and Grouped Summaries duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Abu Bokkor Shiddik [ABS798](ধুমকেতু-মৈনাক) 05 Novembro 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 52 vezes e gostou 1 espectadores. Boa visualização!