Aim and Alogrorithm - Full
Aim and Alogrorithm - Full
Aim:
To write a python pandas program to create a Panda’s Series from a dictionary of values and a
ndarray.
Algorithm:
Aim:
To write a python pandas program to create a Series and then add new records and remove
existing record from the Series.
Algorithm
Step 1: Start the program
Step 2: import the pandas library
Step 3: Create dictionary d with student Name amd Marks
Step 4: Create the series using the dictionary d
Step 5: Print the dictionary
Step 6: Add a new record using the following statement :
serieseObject[index] = value
Step 7: Print the Series
Step 8: Remove the record using the following statement
seriesObject = seriesObject.drop(index)
Step 9: Print the Series
Step 10: Stop the program
Aim:
To write the python pandas program to update a record of a Series.
Algorithm:
Step 1: Start the program
Step 2: import the pandas library
Step 3: Create dictionary d with student Name amd Marks
Step 4: Create the series using the dictionary d
Step 5: Print the Series.
Step 6: To update the record use the following statement
seriesObject[index] = newValue
Step 7: Print the update series
Step 8: Stop the programs
4. Display the records of students who have scored marks above 90 from data stored in pandas
Series.
Aim:
To write a python pandas program that would print the records of students who have scored marks
above 90 from the data stored in Series.
Algorithm:
Step 1: Start the program
Step 2: import the pandas library
Step 3: Create dictionary d with student Name and Marks
Step 4: Create the series using the dictionary d
Step 5: Print the Series.
Step 6: To filter and print the records, use the following command
print(seriesObject[filterCondition])
Step 7: Stop the programs
Aim:
To write a python program that would
Algorithm:
Step 1: Start the program
Step 2: import the pandas library
Step 3: Create dictionary d with employee details of form employeeName and Salary
Step 4: Create the series using the dictionary d
Step 5: Print the Series.
Step 6 : Increment the salary by 10% using the following statements
seriesObject = seriesObject + seriesObject * 10/100
Step 7: Print the Series containing the updated salary
Step 8: Stop the process.
Aim:
To write a python pandas program to perform arithmetic operation on two Pandas Seires.
Algorithm:
Step 1: Start the program
Step 2: import the pandas library
Step 3: Create two Series ds1 and ds2, each containing 5 numeric values
Step 4: Add the two series d = ds1 + ds2 and print the result
Step 5: Subtract the two series d = ds1 – ds2 and print the result
Step 6: Multiply the two series d = ds1 * ds2 and print the result
Step 7: Divide the two series d = ds1 / ds2 and print the result
Step 8: Stop the program.
7. Create a DataFrame using list of list and display its row labels, column labels, data types of
each column and their dimensions
Aim: To write a python program to create a DataFrame and display its row labels, column labels, data
types of each column and their dimensions
Algorithm:
Step 1: Start the program
Step 2: import the pandas module
Step 3: Create list “exam_data” contains the student exam results as data in it.
Step 4: Create a DataFrame ‘exam_result’ using the above list ‘exam_data’
Step 5: Print the exam_result DataFrame
Step 6: Print the column labels using the command – exam_result.columns.values
Step 7: Print the row labels using the command – exam_result.index.values
Step 8: Print the datatype of columns using the command – exam_result.dtypes
Step 9: Print the dimension using the command – exam_result.ndim
Step 10: Print the row and column dimension using the command – exam_result.shape
Step 11: Stop the program
8. Create a DataFrame using List of Numpy array and then add a new Column and a Row to it.
Aim:
To write a python program to create a DataFrame using List of Numpy array and then add a column
and a row to it.
Algorithm:
Step 1: Start the program
Step 2: import the pandas module
Step 3: Create the given DataFrame using list of Numpy array
Step 4: Print the DataFrame
Step 5: Add a new column with names as “Accountancy” and values as [92,86,95,79]
Step 6: Print the DataFrame
Step 7: Add add a new row with index as 'Sunitha' and values as [88,90,78]
Step 8: Print the DataFrame
Step 9: Stop the program
9. Create a DataFrame using List of Dictionary and then delete a column and a row from it
Aim: To write a python program to create a DataFrame using List of Dictionary and then delete a
column and a row from it.
Algorithm:
Step 1: Start the program
Step 2: import the pandas module
Step 3: Create the given DataFrame using List of Dicionary
Step 4: Print the DataFrame
Step 5: Remove the column “Accountancy” using the drop function
Step 6: Print the DataFrame
Step 7: Remove the record of ‘Chandra' using the drop function
Step 8: Print the DataFrame
Step 9: Stop the program
10. Create a DataFrame using Dictionary of List and then change the row index label and
column name
Aim:
To create a DataFrame using Dictionary of List and then change the row index label and column
name.
Algorithm:
Step 1: Start the program
Step 2: import the pandas module
Step 3: Create the given DataFrame using using Dictionary of List
Step 4: Print the DataFrame
Step 5: Change the city name “Chennai” to “Kolkatta” using the rename function
Step 6: Print the DataFrame
Step 7: Change the column name ‘Avgtemp' to “MeanTemp” using the rename function
Step 8: Print the DataFrame
Step 9: Stop the program
Algorithm:
Step 1: Start the program
Step 2: Import the required modules: pandas and numpy
Step 3: Create a dictionary with keys "Name", "Perc", and "Qualify"
Step 4: Define a list of labels to be used as row indices
Step 5: Create the DataFrame using the dictionary and index
Step 6: Display the original DataFrame
Step 7: Accept a row index label from the user
Step 8: Accept a new percentage value from the user
Step 9: Update the "Perc" column for the specified index using .loc[]
Step 10: Display the updated DataFrame
Step 11: Stop the program
Aim:
To write a python pandas program to import and export data from CSV file
Algorithm:
Step 1 : Start
Step 2 : Import the Pandas library.
Step 3 : Read the CSV file "Employee.csv" into a DataFrame.
Step 4 : Print the original DataFrame.
Step 5 : Create a new column "Tot_sal" and calculate the sum of "Salary", and "Incentive".
Step 6 : Print the updated DataFrame.
Step 7 : Save the updated DataFrame to a new CSV file named "Employee2.csv".
Step 8 : End
Program 15:
Update Employee Salary and Save to CSV
Aim:
To write a python pandas program to import a csv file containing salary details, update the salary
and then export the updated data to csv file.
Algorithm:
Step 1 : Start
Step 2 : Import the Pandas library
Step 3 : Read the CSV file into a DataFrame
Step 4 : Print the original DataFrame
Step 5 : Increase the "Salary" by 2000
Step 6 : Print the updated DataFrame
Step 7 : Reduce the "Incentive" by 5%
Step 8 : Print the updated DataFrame
Step 9 : Save the updated DataFrame to a new CSV file
Step 10 : End
Program 16:
Plot Line Chart for Marks Scored in Different Subjects
Aim:
To write a python program using Matplotlib library to plot a line chart for Marks scored in different
subjects.
Algorithm:
Step 1: Start
Step 2: Import the matplotlib.pyplot library as plt to enable plotting.
Step 3: Create the list subject with the names of subjects
Step 4: Create the list marks with the corresponding marks for each subject
Step 5: Create a plot using the plt.plot() function using subject and marks data
Step 6: Set the title of the plot using plt.title('Marks scored').
Step 7: Label the x-axis as "Subject" using plt.xlabel('Subject').
Step 8: Label the y-axis as "Marks" using plt.ylabel('Marks').
Step 9: Display the plot on the screen using plt.show().
Step 10: End
Program 17:
Bar Chart of Games Tally in State Level Sports
Aim:
To write a python program using Matplotlib library to plot a Bar chart depicting the Games tally in
state level sports.
Algorithm:
Step 1 : Start
Step 2 : Import the matplotlib.pyplot library as plt to enable plotting.
Step 3 : Create the list games consisting names of the games.
Step 4 : Create another list named no_of_games denoting number games played.
Step 5 : Plot the bar chart using the plt.bar() with the data of games and no_of_games.
Step 6 : Set the x-axis label as "Game Name" using `plt.xlabel()`.
Step 7 : Set the y-axis label as "Number of games" using `plt.ylabel()`.
Step 8 : Set the title as "Number of games Tally in State Level Sports" using `plt.title()`.
Step 9 : Use `plt.savefig("Games.png")` to save the plot.
Step 10 : Display the plot using `plt.show().
Step 11 : End
Program 18:
Histogram of Daily Temperatures in a Month
Aim:
To write a python program using Matplotlib library to plot a Histogram chart to depict the daily
temperatures in a month.
Algorithm:
Step 1 : Start
Step 2 : Import the matplotlib.pyplot module as plt for creating the histogram.
Step 3 : Create a list, temperatures, containing the daily temperature readings.
Step 4 : Specify the Bins
Step 5 : Create the Histogram using plt.hist() to generate a histogram with values temperatures and
bins.
Step 6 : Use plt.xlabel() to label the x-axis as "Temperature Ranges (°C)".
Step 7 : Use plt.ylabel() to label the y-axis as "Frequency".
Step 8 : Use plt.title() to add a title to the chart: "Daily Temperatures in a Month".
Step 9 : Use plt.show() to display the histogram chart.
Step 10 : End
Program 19:
Plotting Multiple Lines: Weekly Sales of Cotton and Jeans
Aim:
To write a python program using Matplotlib library to plot two lines on a line chart showing weekly
sales of Cotton and Jeans clothes.
Algorithm:
Step 1 : Start
Step 2 : Import matplotlib.pyplot for plotting.
Step 3 : Create lists for days of the week and sales data for cotton and jeans.
Step 4 : Use plt.plot() to plot cotton sales with a green dotted line and '+' markers.
Step 5 : Use plt.plot() to plot jeans sales with a magenta dash-dot line and 'x' markers.
Step 6 : Use plt.title() to add the chart title "Weekly Sales Report."
Step 7 : Label the x-axis as "Days" and the y-axis as "Orders" using plt.xlabel() and plt.ylabel().
Step 8 : Add a legend for cotton and jeans using plt.legend().
Step 9 : Use plt.show() to render and display the chart.
Step 10 : End
Program 20:
Plotting Bar chart using DataFrame
Aim:
To write a python program using Matplotlib library to plot a Bar chart using the DataFrame plot
function.
Algorithm:
Step 1 : Start
Step 2 : Import pandas and matplotlib.pyplot for data manipulation and plotting.
Step 3 : Use pd.read_csv() to load the CSV file Sales.csv into a DataFrame named df.
Step 4 : Use the plot() method to create a bar chart with the x-axis as 'Day', and set bar colors, edge
color, line width, and style.
Step 5 : Label the y-axis as "Sales in Rs." using plt.ylabel().
Step 6 : Add the chart title "Mela Sales Report" using plt.title().
Step 7 : Use plt.show() to render and display the bar chart.
Step 8 : End