Pandas - DataFrames

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 13:- Pandas - DataFrames

In Pandas, a DataFrame is a two-dimensional tabular data structure that represents data in a spreadsheet-like format. It consists of rows and columns, and each column can contain data of different types. DataFrames are a primary data structure used in Pandas for data manipulation, analysis, and cleaning. They offer a wide range of functionalities and are often used for data preparation and exploratory data analysis in data science and data analysis tasks.

Creating a DataFrame: There are several ways to create a DataFrame in Pandas. Here are some common methods:

From a Dictionary: You can create a DataFrame from a Python dictionary, where each key represents a column name and each value represents the column's data. The dictionary keys will become the column labels, and the values will populate the rows of the DataFrame.

From a List of Lists or NumPy Array: You can create a DataFrame from a list of lists or a NumPy array. Each inner list represents a row, and the outer list contains all the rows.

From a CSV or Excel File: You can read data from a CSV or Excel file and create a DataFrame using pd.read_csv() or pd.read_excel() functions.

Common DataFrame Operations: Once you have a DataFrame, you can perform various operations on it, such as:

  • Accessing columns and rows: df['column_name'], df.loc[row_index], df.iloc[row_index]
  • Filtering rows based on conditions: df[df['column_name'] > 30]
  • Adding and deleting columns: df['new_column'] = [value1, value2, value3], del df['column_to_delete']
  • Summary statistics: df.describe(), df.mean(), df.max(), etc.
  • Sorting data: df.sort_values(by='column_name')
  • Grouping and aggregation: df.groupby('column_name').sum()
  • Merging and joining DataFrames: pd.merge(df1, df2, on='common_column')

These are just a few examples of the powerful operations you can perform with Pandas DataFrames. Pandas provides extensive documentation and tutorials, making it easy to work with data in DataFrames and perform complex data manipulations efficiently.

 

pythonCopy code

import pandas as pd # Read data from a CSV file df = pd.read_csv('data.csv') # Read data from an Excel file df = pd.read_excel('data.xlsx')

pythonCopy code

import pandas as pd data = [    ['Alice', 25, 'New York'],    ['Bob', 30, 'London'],    ['Charlie', 35, 'San Francisco'] ] df = pd.DataFrame(data, columns=['Name', 'Age', 'City'])

pythonCopy code

import pandas as pd data = {    'Name': ['Alice', 'Bob', 'Charlie'],    'Age': [25, 30, 35],    'City': ['New York', 'London', 'San Francisco'] } df = pd.DataFrame(data)

2. Handling Data

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?