×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Python Program to Perform Data Analysis Assignment Solution

June 13, 2024
Dr. Nicole
Dr. Nicole
🇬🇧 United Kingdom
Python
Dr. Nicole, an accomplished professional with 6 years of experience, obtained her Ph.D. from Princeton University. Having completed over 400 Python assignments, she brings a wealth of expertise and insight to the table. With a focus on clarity and precision, Dr. Nicole is committed to providing comprehensive support to students seeking assistance with their Python projects.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Familiarize yourself with OCaml's pattern matching; it simplifies handling recursive data structures like lists and trees, making your code concise and easier to debug.
News
In 2024, Girls Who Code introduced a Data Science + AI track in their free summer programs for high school students, fostering skills in cybersecurity and creative coding​

Instructions

Objective

Write a Python assignment where students are required to create a program to perform data analysis in Python. This assignment will challenge students to utilize their programming skills to manipulate and analyze datasets, apply statistical techniques, and present their findings effectively. By completing this assignment, students will not only strengthen their Python programming abilities but also gain valuable experience in handling real-world data analysis tasks..

Requirements and Specifications

program-to-perform-data-analysis-in-python

Source Code

# Part 2 - Project Final Report --- ## ** PLEASE READ: ** This document provides a template that you can elect to fill in or modify for your project report. The sectioning (header structure) is not strict, and you are encouraged to adjust it to suit your project. #### General guidelines The objective of your final report is to provide a thorough overview of your project. It need not be long; quality and clarity is preferred over quantity. **Aim for 3-5 pages**; if you feel that further material needs to be included, you can add an appendix with supplementary information, tables, and plots. #### Contents The report should include the following elements: * Abstract + One-paragraph summary of the report contents. * Background + Adapt your interim report. * Aims + State the specific questions and approaches you took up. * Data description + Adapt your interim report. + Possibly include select results of your exploratory analysis. * Methods + Description of the methods used in your analysis. * Results + Present the figures and tables summarizing your analysis. * Discussion + Highlight your main findings and takeaways. + Offer further commentary: caveats, further steps, etc. These need not be set apart by headers; you are free to determine how to organize your report. #### Format and appearance * No codes should appear in your report. * All figures and tables should have captions. * Figures should be appropriately sized and labeled. * The total length should not exceed 8 pages. ### Evaluation Your report will be evaluated based on: * (format) adherence to formatting and appearance guidelines; * (clarity) clarity and thoughtfulness in written voice; * (accuracy) apparent accuracy of quantitative results and technical information; * successful use of one or more techniques in the course. Notice that no credit is tied to the nature of the results; you can earn credit equally well with an analysis that says little as with one that says a lot. **Negative, neutral, or ambiguous results -- analyses that do not produce any particular insight -- are more than acceptable.** If your analyses turn in one of these directions, present them as clearly as possible, and consider speculating in your discussion section about the absence of signficicant/interpretable findings. --- #### Start your project below --- # Relationship between the increase in the consumption of renewable energies and the reduction of CO2 emissions #### Abstract Each year, countries around the world are adopting more renewable energy generation measures to minimize CO2 emissions, which are the main cause of global warming. Despite the fact that there is scientific evidence that global warming is real and its effects are already visible on our planet, there are many people and organizations that do not believe in it or ignore it since their own (economic) interests are more important. . In this work it is possible to demonstrate that there is a clear relationship between the use of renewable energy and the reduction of CO2 emissions, which reduces the greenhouse effect and slows down global warming. --- ## Introduction The use of electricity in homes has become essential in all countries of the world. Electric power is a vital service for our lives, as well as vital for a country to grow. At the same time, electrical energy is generated mostly through the use of fossil fuels such as Coal, Gasoline, Diesel, Natural Gas, etc. These fuels generate CO2 emissions into the environment which have proven to be the main cause of global warming and pollution of the air we breathe. In recent years, the use of renewable energy has been increasingly adopted to reduce CO2 emissions. In this project, two datasets will be used that will be related. The datasets used in this work contain information on the use of renewable energy through the years [1] and the CO2 emissions through the years [2]. In this work we want to demonstrate the direct relationship that exists between the use of renewable energy and the reduction on CO2 emissions. --- ## Materials and methods In this work, two datasets will be used. It has been decided to work with two datasets that are related since both have the same structure and variables. The first dataset contains data on Renewable Energy Consumption (% of total final energy consumption) for all countries in the world and for each year from 1960 to 2021. The second dataset contains data on CO2 Emission (tons per capita) for all countries in the world and for each year from 1960 to 2021. Both datasets were obtained from The World Bank Data In the case of Renewable Energy Consumption, the values obtained refer to the annual average consumption of renewable energy divided by the total annual average consumption of electrical energy in each country. This value is not measured with scientific equipment, but is reported directly by electricity generating companies. In the case of CO2 Emissions, these values are obtained at the Oak Ridge National Laboratory through measurements with specialized scientific equipment for this task. These types of measurements belong to research on climate change. Both datasets contain values grouped by country, and obtained for each year. That is, there is a value for each year and for each country. The time window used in both datasets goes from the year 1960 to 2021, for a total of 61 measurements per country, for a total of 266 countries. import pandas as pd import matplotlib.pyplot as plt import altair as alt ### Load Datasets # load tidied data and print rows # Load the first dataset data1 = pd.read_csv('renewable_energy_consumption.csv', skiprows = 4).drop(columns=['Country Code', 'Indicator Name', 'Indicator Code', 'Unnamed: 66']) data1 = data1.fillna(0) data2 = pd.read_csv('co2_emissions_tpc.csv', skiprows = 4).drop(columns=['Country Code', 'Indicator Name', 'Indicator Code', 'Unnamed: 66']) data2 = data2.fillna(0) Because there are around 264 countries, the graphs will look too saturated, so we will only focus on certain countries specified in the list below countries = ['United States', 'China', 'India', 'Japan', 'Autralia', 'Germany', 'Brazil', 'Canada', 'France', 'Italy', 'Russia'] data1 = data1[data1['Country Name'].isin(countries)] data2 = data2[data2['Country Name'].isin(countries)] ### Show the first 5 rows of the first dataset. The second dataset contains exactly the same columns data1.head() ### Figure 1 First, we show line graphs of both Renewable Energy Consumption and CO2 Emissions for each Country fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize=(15,10)) data1.set_index(['Country Name']).transpose().plot(ax = ax[0]) data2.set_index(['Country Name']).transpose().plot(ax = ax[1]) ax[0].set_xlabel('Year') ax[0].set_ylabel('Renewable Energy Consumption (kWh)') ax[0].grid(True) ax[0].set_title('Renewable Energy Consumption vs. Year') ax[1].set_xlabel('Year') ax[1].set_ylabel('CO2 Emissions (Tons)') ax[1].grid(True) ax[1].set_title('CO2 Emissions vs. Year') We want to see how much each country has adopted the use of Renewable Energy and how much its CO2 Emission changed from the year of the first measurement to the year of the last measurement. dt1 = [] dt2 = [] # Loop over countries for i in range(len(data1)): # Check first column with a measurement country = data1.iloc[i,0] sub = data1.iloc[i,1:] first_yr = -1 first_meas = -1 last_yr = -1 last_meas = -1 for j, col in enumerate(sub): if col > 0: first_yr = 1960+j first_meas = col #print(country, 1960+j, col, sub[-4], sub[-4]/col) break for j, col in enumerate(sub): if sub[len(sub)-1-j] > 0: last_yr = 2021-j last_meas = sub[len(sub)-1-j] break dt1.append([country, first_yr, last_yr, first_meas, last_meas,(last_meas/first_meas - 1.0)*100.0]) for i in range(len(data2)): # Check first column with a measurement country = data2.iloc[i,0] sub = data2.iloc[i,1:] first_yr = -1 first_meas = -1 last_yr = -1 last_meas = -1 for j, col in enumerate(sub): if col > 0: first_yr = 1960+j first_meas = col #print(country, 1960+j, col, sub[-4], sub[-4]/col) break for j, col in enumerate(sub): if sub[len(sub)-1-j] > 0: last_yr = 2021-j last_meas = sub[len(sub)-1-j] break dt2.append([country, first_yr, last_yr, first_meas, last_meas,(last_meas/first_meas - 1.0)*100.0]) data_renewable = pd.DataFrame(data=dt1, columns = ['Country', 'First Year', 'Last Year', 'First Measurement', 'Last Meaurement', 'Change']) data_co2 = pd.DataFrame(data=dt2, columns = ['Country', 'First Year', 'Last Year', 'First Measurement', 'Last Meaurement', 'Change']) ### Figure 2 fig = plt.figure() # Create matplotlib figure ax = fig.add_subplot(111) # Create matplotlib axes ax2 = ax.twinx() # Create another axes that shares the same x-axis as ax. width = 0.4 data_renewable[['Country', 'Change']].set_index(['Country']).plot(kind='bar', color='red', ax=ax, width=width, position=1, label = 'Renewable') data_co2[['Country', 'Change']].set_index(['Country']).plot(kind='bar', color='blue', ax=ax2, width=width, position=0, label = 'CO2') ax.set_ylabel('Change in use of Renewable Energy (%)') ax2.set_ylabel('Change in CO2 Emissions (%)') We can see that countries like Germany, Italy France and the United States have adopted the use of energy and at the same time reduced CO2 emissions. The red bars represent the change in the use of Renewable Energy from the first year to the last year in which measurements were recorded. The blue bar represents the change in CO2 emissions. If the bar is on the positive axis, it means that the change was positive, that is, there is a greater use of renewable energy/CO2 emissions. We can see in countries like Germany, that the use of renewable energy increased greatly and the number of CO2 emissions was reduced. On the other hand, countries like China have achieved the opposite, as the use of renewable energy decreased while CO2 emissions increased drastically. ### Figure 3 Finally, to demostrate that the relation between the Renewable Energy Consumption and the CO2 Emissions is inverse, we can compute the correlation between the two datasets for each year. If we are correct, we should obtain only negative values (negative correlation means that, as one variable increases, the other decreases) fig, ax = plt.subplots() data1.corrwith(data2).dropna().plot(ax = ax) plt.xlabel('Year') plt.ylabel('Correlation') plt.grid(True) plt.title('Correlation vs. Year') plt.show() --- ## Results ### Figure 1 In the first Figure we can see an example of the measurements contained in both datasets. The first dataset contains measurements on the consumption (kWh) of Renewable Energies through the years, and this can be seen in the graph on the right. The second dataset contains measurements on CO2 emissions (tons) over the years, and this graph can be seen in the graph on the left. Both graphs are shown for the selected countriers, where we can see which countries has the higher increase/decrease over the years. That graph clearly shows that for countries that have adopted responsibility for renewable energy use, as renewable energy use increases, CO2 emissions decrease, and vice-versa. ### Figure 2 The second graph is one of the most important and shows the change that certain countries have undergone regarding the adoption of the use of Renewable Energy and CO2 emissions. This graph takes the first measurement (the first year recorded) and the last measurement (the last year recorded) and based on these values calculates the percentage of change between both measurements, in order to illustrate how much energy use has decreased or increased. Renewable and CO2 Emissions from the beginning of the measurements to the present. It was previously mentioned that, although the dataset contains information for 264 countries, to prevent the graphs from looking saturated, a list of countries of interest has been selected. Figure 2 has two bars per country: one red and one blue. The red bar represents the change in the use of Renewable Energy while the blue bar represents the change in CO2 emissions. A positive value indicates that the change is positive (ie increased) while a negative value indicates that the value decreased. ### Figure 3 Finally, in Figure 3 we can see the correlation between both datasets for each year. What this graph really shows is the relationship between the consumption of Renewable Energy and CO2 emissions for each country. As mentioned above, the relationship is inverse, which translates into a negative correlation. --- ## Discussion In this work, two individual datasets were analyzed in order to determine a relationship between them. The analyzed datasets contain information on the use of Renewable Energy (in kWh) and CO2 Emissions (tons) measured for each country over the years. It is known that CO2 emissions are directly related to the generation of electricity due to the use of fossil fuels such as coal, wood, gasoline, diesel, etc. Renewable energies come from clean sources such as Solar Energy, Wind Energy, and other clean energy sources that do not generate CO2 emissions, so as energy generation from fossil fuels migrates to clean sources, emissions of CO2 should decrease. In this work it has been satisfactorily demonstrated that there is a clear relationship between CO2 emissions and the use of Renewable Energy. We could see in Figures 1 and 2 that, as the use of renewable energies increased, CO2 emissions decreased. Similarly, if the use of renewable energy decreases, CO2 emissions increase. Figure 3 is the clearest proof of the inverse relationship between both variables. Although Figure 1 and 2 show a visual relationship that can be interpreted by the reader, Figure 3 shows a statistical test that was done by calculating the correlation, which is negative, indicating that the relationship is inversely proportional. --- ## End of Project Save as idynb file, and also export as both html and pdf files.

Similar Samples

Check out our sample solutions to get a glimpse of the high-quality work we provide. Our examples cover a range of programming tasks and languages, demonstrating our expertise and commitment to delivering top-notch programming homework help. See for yourself why our clients trust us with their assignments.