0% found this document useful (0 votes)
16 views23 pages

Actuators and Drivers

Uploaded by

raghav3032005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views23 pages

Actuators and Drivers

Uploaded by

raghav3032005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Python Pandas

Pandas
• Pandas is an open – source Python library that has functions
providing high performance data manipulation and analysis. Prior
to Pandas, Python had very little contribution toward data
analysis. But with Pandas solved, Python can be used to load,
prepare, manipulate, model and analyze data.
Data frame- A key component of Python
• A data frame is a two-dimensional data structure in which data are
organized in a tabular fashion using rows and collumns. Basic
features of data frame can be given as
• Columns of different data types
• Size is mutable
• Data frame has labelled axes for rows and columns
• Arithmetic operations can be performed on rows and columns
Creating a data frame
Example 1
Example 2
Example 3
Pandas Dataframe functions and attributes
Functions and attributes
Read And Write Csv File Using Pandas Showing
Examples
Introduction to Pandas and CSV Files

• Pandas is a powerful data manipulation library in Python.

• It provides easy-to-use functions for reading and writing data in various


formats, including CSV.

• CSV (Comma-Separated Values) files are widely used for data storage and
exchange due to their simplicity.
Reading a CSV File

• To read a CSV file, you can use the `pd.read_csv()` function.

• This function takes the file path as an argument and returns a DataFrame.

• For example: `df = pd.read_csv('data.csv')` reads the CSV file into a


DataFrame named `df`.
Displaying Data

• After loading the CSV file into a DataFrame, you can display the first few
first few rows using `df.head()`.

• This method is helpful for quickly inspecting the data structure.

• For instance, calling `df.head()` will show the first five rows of the
DataFrame.
Writing to a CSV File

• You can write a DataFrame to a CSV file using the `to_csv()` method.

• This method allows you to specify the filename and various options, such
as including headers.

• For example: `df.to_csv('output.csv', index=False)` writes the DataFrame to


'output.csv' without the index.
Reading with Custom Delimiters

• The `read_csv()` function supports custom delimiters beyond commas.

• You can specify a different delimiter using the `sep` parameter.

• For example: `pd.read_csv('data.tsv', sep='\t')` reads a tab-separated file.


Handling Missing Values

• Pandas provides options to deal with missing values when reading CSV
files.

• You can use the `na_values` parameter to specify additional strings to treat
as NaN.

• For example: `pd.read_csv('data.csv', na_values=['NA', 'N/A'])` treats 'NA'


and 'N/A' as missing values.
Writing Without Headers

• If you want to write a DataFrame to CSV without including headers, you


can set the `header` parameter to `False`.

• This can be useful when the target application does not require headers.

• For example: `df.to_csv('output.csv', header=False)` writes the DataFrame


without headers.
Advanced Reading Options

• The `read_csv()` function has several advanced options for reading data.

• You can specify the `usecols` parameter to read only specific columns from
the CSV file.

• For example: `pd.read_csv('data.csv', usecols=['Column1', 'Column2'])`


reads only the specified columns.
Conclusion

• Pandas makes it simple to read and write CSV files effectively.

• Understanding the various options available can enhance your data


manipulation capabilities.

• Practice using these functions to become proficient in handling CSV data


with Pandas.

You might also like