Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

Python For Data Analysis

Uploaded by

Samyucktha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Python For Data Analysis

Uploaded by

Samyucktha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Introduction to Python

Python is an easy-to-read, high-level, interpreted programming language known for its simplicity
and versatility.

2. Variables and Data Types

● Variables store data values. In Python, you don’t need to declare the type of a variable,
as it is dynamically typed.
● Data Types: Python has several built-in data types including:
○ Integers (int)
○ Floating point numbers (float)
○ Strings (str)
○ Lists (list)
○ Dictionaries (dict)
○ Tuples (tuple)
○ Booleans (bool)

3. Basic Syntax
Comments: Use # for single-line comments and triple quotes for multi-line comments.
python
# This is a single-line comment
"""
This is a
multi-line comment
"""

Print Statement: Display output using print().


python
print("Hello, World!")

4. Control Flow
If Statements: Used to execute code based on conditions.
python
if condition:
# code
elif another_condition:
# code
else:
# code

5. Loops
For Loops: Iterate over a sequence.
python
for element in sequence:
# code

While Loops: Repeat code as long as a condition is true.


python
while condition:
# code

6. Functions

Functions are blocks of reusable code.

python
def function_name(parameters):
# code
return value

7. Libraries and Modules

You can extend Python’s functionality with libraries and modules using import.

python
import math
print(math.sqrt(16)) # Outputs 4.0

8. Basic Input/Output
Input: Get user input using input().
python
name = input("Enter your name: ")
print("Hello, " + name)

9. Error Handling

Handle errors using try and except.

python
try:
# code that might raise an error
except Exception as e:
print("An error occurred:", e)

10. File Handling

Read and write files using built-in functions.

python
with open('file.txt', 'r') as file:
content = file.read()

This should give you a solid foundation. If you need more details on any specific topic, feel free
to ask!

Notes on python for data analysis

Absolutely, here are some key points about using Python for data analysis:

1. Libraries for Data Analysis

Python has several powerful libraries designed specifically for data analysis:

● NumPy: Fundamental package for numerical computations.


● Pandas: Provides data structures and functions needed to work with structured data
seamlessly.
● Matplotlib: Plotting library for creating static, animated, and interactive visualizations.
● Seaborn: Statistical data visualization library based on Matplotlib, offering an
easy-to-use interface.
● SciPy: Library used for scientific and technical computing.
● Scikit-learn: Library for machine learning, offering simple and efficient tools.

2. Data Structures
Arrays (NumPy): Efficient storage and operations for large datasets.
python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])

DataFrames (Pandas): Two-dimensional, size-mutable, and potentially heterogeneous tabular


data.
python
import pandas as pd
df = pd.DataFrame({
'A': [1, 2, 3],
'B': [4, 5, 6],
})

3. Data Manipulation with Pandas


Loading Data: Read data from various file formats like CSV, Excel, etc.
python
df = pd.read_csv('file.csv')

Inspecting Data: Methods to understand the data.


python
df.head() # Displays first few rows
df.describe() # Statistical summary
df.info() # Information about DataFrame

Handling Missing Data: Techniques to deal with missing data.


python
df.dropna() # Remove missing values
df.fillna(0) # Replace missing values

Filtering and Sorting Data:


python
filtered_df = df[df['A'] > 1] # Filter rows
sorted_df = df.sort_values(by='A') # Sort by column


4. Data Visualization
Matplotlib: Basic plotting.
python
import matplotlib.pyplot as plt
plt.plot(df['A'], df['B'])
plt.show()

Seaborn: Advanced visualization.


python
import seaborn as sns
sns.scatterplot(x='A', y='B', data=df)
plt.show()

5. Data Analysis and Statistical Techniques


Descriptive Statistics: Mean, median, mode, standard deviation, etc.
python
df['A'].mean()
df['A'].std()

Correlation and Regression: Understanding relationships between variables.


python
df.corr() # Correlation matrix

6. Machine Learning with Scikit-learn


Importing models: Example of using linear regression.
python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)

● predictions =

You might also like