ALL PYTHON FUNCTIONS AND STATEMENTS
1)PANDAS SERIES:
1. Creation of Series:
- from ndarray
4. Indexing: series[2]
[Link]([Link]([1, 2, 3, 4, 5])) 5.) Slicing: series['b':'c']
- from dictionary 2)Pandas DataFrames:
[Link]({'a': 10, 'b': 20, 'c': 30})
1. Creation:
- from scalar value
- from dictionary of Series
[Link](5, index=['a', 'b', 'c'])
[Link]({'Name': series, 'Age': [25, 30, 35]})
- from list of dictionaries
[Link] Operations: [Link]([{'Name': 'Alice', 'Age': 25}, {'Name':
Addition: 'Bob', 'Age': 30}])
Example: result = series1 + series2 - from Text/CSV files
Subtraction: pd.read_csv('[Link]')
Example: result = series1 - series2
Multiplication: 2. Display and Iteration:
Example: result = series1 * series2 print(df)
Division: for index, row in [Link]():
Example: result = series1 / series2 print(row['Name'], row['Age'])
3. Methods of Series: 3. Operations on Rows and Columns:
1. Head Function: - Add a new column
- Purpose: Displays the first n rows of the df['City'] = ['New York', 'San Francisco', 'Los
DataFrame. Angeles']
- Example: df_head = [Link](5) - Selecting columns
2. Tail Function: selected_column = df['Column_Name']
- Purpose: Displays the last n rows of the - Deleting rows
DataFrame.
df = [Link](1)
- Example: df_tail = [Link](3)
- Rename columns
3. count():
df_renamed = [Link](columns={'Old_Name':
- Purpose: Returns the number of non-null (non- 'New_Name'})
missing) values in a Pandas Series or DataFrame.
- Example: 4. Head and Tail Functions:
series_count = [Link]() [Link]()
df_column_count = df['Column_Name'].count() [Link](2)
5. Indexing using Labels and Boolean [Link]()
Indexing: 4. Histogram:
[Link][0]
- Explanation: Shows the distribution of a dataset.
df[df['Column_Name'] > 30]
- Example:
3) Importing/Exporting Data data_for_hist = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5]
between CSV Files and [Link](data_for_hist, bins=5)
DataFrames: [Link]()
- Reading from CSV files: 5. Customizing Plots:
pd.read_csv('[Link]') - Adding Labels:
- Writing to CSV files: [Link]('X-axis Label')
df.to_csv('new_filename.csv', index=False) [Link]('Y-axis Label')
- Adding Title:
[Link]('Title of the Plot')
4) Data Visualization with
- Adding Legend:
Matplotlib:
[Link](x, y, label='Line 1')
1. Purpose of Plotting:
[Link]()
- Explanation: Visualize data to understand
patterns, trends, and relationships. 6. Drawing and Saving Plots:
- Example: - Explanation: Saves plots as image files.
import [Link] as plt - Example:
2. Line Plot: [Link](x, y)
[Link]('scatter_plot.png')
- Explanation: Represents data points with lines.
[Link]()
- Example:
x = [1, 2, 3, 4, 5]
y = [10, 12, 5, 8, 6] 4)Common Attributes(BOTH):
[Link](x, y)
[Link]() 1. index:
3. Bar Graph: - Purpose: Returns the index (labels) of the Series
or DataFrame.
- Explanation: Displays data using bars of
different heights. - Example:
- Example: series_index = [Link]
categories = ['Category A', 'Category B', 'Category df_index = [Link]
C']
values = [20, 30, 25]
2. values:
[Link](categories, values)
- Purpose: Returns the array of values in the
Series or DataFrame.
7. ndim:
- Example:
- Purpose: Returns the number of dimensions (1
series_values = [Link] for Series, 2 for DataFrame).
df_values = [Link] - Example:
series_ndim = [Link]
3. size: df_ndim = [Link]
- Purpose: Returns the number of elements in
the Series or DataFrame.
5)Additional DataFrame
- Example:
Attributes:
8. columns:
series_size = [Link]
- Purpose: Returns the column labels of the
df_size = [Link]
DataFrame.
- Example:
4. empty:
df_columns = [Link]
- Purpose: Returns True if the Series or DataFrame
is empty, and False otherwise.
9. axes:
- Example:
- Purpose: Returns a list with the row axis labels
series_empty = [Link]
and column axis labels.
df_empty = [Link]
- Example:
df_axes = [Link]
5. dtype:
- Purpose: Returns the data type of the values in
10. dtypes:
the Series or DataFrame.
- Purpose: Returns the data type of each column
- Example:
in the DataFrame.
- Example:
series_dtype = [Link]
df_dtypes = [Link]
df_dtypes = [Link]
11. T (Transpose):
6. shape:
- Purpose: Transposes the DataFrame,
- Purpose: Returns a tuple representing the interchanging rows and columns.
dimensionality of the Series or DataFrame.
- Example:
- Example:
df_transposed = df.T
series_shape = [Link]
df_shape = [Link]