Course Content
Python Indentation, Comments and Variables
0/2
Object Oriented Programming in Python
0/1
Exception Handling in Python
0/1
Sending emails with Python
0/1
Unit test in python programming
0/1
Python programming (zero to advance!!!)
About Lesson

DATAFRAME:

The DataFrame is the primary data structure in Pandas. It represents tabular data similar to a spreadsheet with rows and columns. DataFrames allow for easy manipulation, filtering, and analysis of structured data.
A DataFrame is a two-dimensional labeled data structure in Pandas, similar to a table or spreadsheet in Excel. It consists of rows and columns, where each column can have a different data type. DataFrames are commonly used for data manipulation, analysis, and exploration in Python.

Here’s an illustrative code example of creating a DataFrame in Python using Pandas:

“`python
import pandas as pd

# Create a dictionary with data
data = {
‘Name’: [‘John’, ‘Anna’, ‘Peter’, ‘Linda’],
‘Age’: [28, 35, 40, 25],
‘City’: [‘New York’, ‘Paris’, ‘London’, ‘Sydney’]
}

# Create a DataFrame from the dictionary
df = pd.DataFrame(data)

# Display the DataFrame
print(df)
“`

Output:
“`
Name Age City
0 John 28 New York
1 Anna 35 Paris
2 Peter 40 London
3 Linda 25 Sydney
“`

In this example:
– We first import the Pandas library with the alias `pd`.
– Then, we create a dictionary `data` containing three columns: `’Name’`, `’Age’`, and `’City’`, each with a list of values.
– Next, we create a DataFrame `df` using the `pd.DataFrame()` function, passing the `data` dictionary as an argument.
– Finally, we display the DataFrame using the `print()` function, which prints the contents of the DataFrame to the console.

This creates a DataFrame with four rows and three columns, where each column represents a different attribute (Name, Age, City), and each row represents a different observation or record.

Join the conversation