The document discusses using the pandas read_csv() function to read data from CSV files into a DataFrame. It explains that read_csv() can be used with different arguments like filepath, names, header, and skiprows to control how the data is read and indexed. The document provides examples of using these arguments to specify column names, skip rows, and select different headers for the DataFrame. It also includes examples of using read_csv() to read employee data from a CSV file and perform tasks like finding the maximum salary.
3. We can use read_csv() function to read data from a CSV file in our DataFrame by using
<DF>=pandas.read_csv(<FilePath>)
4.
5. We can use read_csv() function to read data from a CSV file in our DataFrame by using
<DF>=pandas.read_csv(<FilePath>, names=<sequence containing column names>)
6. We can use read_csv() function to read data from a CSV file in our DataFrame by using
<DF>=pandas.read_csv(<FilePath>, names=None>)
If names=None is
specified in read_csv
function, first row
will be taken as
column header in
DataFrame
7. We can use read_csv() function to read data from a CSV file in our DataFrame by using
<DF>=pandas.read_csv(<FilePath>, header=None>)
If header=None is
specified in read_csv
function, column
header in DataFrame
will in labeled as
index form 0,1,2..
and so on.
8. Now ,this not the output we wanted,
We wants an output as following
If, in read_csv() if you want following
output
Then, simply, use the following
<DF>=pandas.read_csv(<FilePath>,
names=<sequence of column headings>,
skiprows=<n>)
9. skiprows argument can take either a
number for rows to be skipped from beginning
or
It can take list of rows number to be skipped
Row 0 will not be
removed , since it
column heading
specified in
names argument
10. We can use read_csv() function to read data from a CSV file in our DataFrame by using
<DF>=pandas.read_csv(<FilePath>, header=None>, skiprow=<n>)
Here, we have specified
“header=None”, the python read all
the rows from CSV file. , column header
in DataFrame will in labeled as index
form 0,1,2.. and so on.
Here, we have specified “skiporws=2”,
the python will skip first 2 rows from
CSV file.
12. Ex 1. Write a program to read from a CSV file employee.csv and create a DataFrame from it.
13. Ex 2. Write a program to read from a CSV file employee.csv and create a DataFrame from it
but DataFrame should not use file’s column header rather should use own column number
as 0,1,2, and so on.
14. Ex. 3 Write a program to read from CSV file employee.csv and create a dataframe from it. Use
Empno column as labels
15. skiprows=1, is not mentioned so,
first row is not eleminted in
output, although, names
argument is passed
Ex 4 Write a program to read from CSV file employee.csv and create a dataframe from it. But
dataframe should not use files columns header rather should own columns heading as
“EmpID”,” EmpName”, “Designation” and “Salary”. Also Print the maximum salary given to an
employee.
16. Ex 4 Write a program to read from CSV file employee.csv and create a dataframe from it. But
dataframe should not use files columns header rather should own columns heading as
“EmpID”,” EmpName”, “Designation” and “Salary”. Also Print the maximum salary given to an
employee.