Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The code needs to be written using pandas. Need some help. I've written my code however, when it comes to performing the data conversions
The code needs to be written using pandas.
Need some help. I've written my code however, when it comes to performing the data conversions I run into issues.
csv file located here: https://drive.google.com/drive/u/0/folders/1bNuaHOs5g2DHSwT3ZoXUCEf2VkgEib87
Using, WburgWeather.csv. do some data wrangling so that they do not need to cleanse the data themselves. Do these tasks:
- Generate a program called M7dataWrang.py to accomplish the steps below. • Read the file into a DataFrame using the first row to determine the column headings. Name the DataFrame dfWeather.
- In reviewing the data, you notice that some data are missing. Convert the temperature data and delete all the rows where the data for these columns is missing because you cannot convert a null value.
- Convert the three columns with Fahrenheit temperature scales to Celsius and rename them accordingly.
- Old Column name: HOURLYDRYBULBTEMPF, New Column name: HOURLYDRYBULBTEMPC
- Old Column name: HOURLYWETBULBTEMPF, New Column name: HOURLYDRYBULBTEMPC
- Old Column name: HOURLYDewPointTempF, New Column name: HOURLYDewPointTEMPC
- You notice that the HOURLYWindDirection column sometimes has entries "VRB" rather than a numerical number for degrees. You contacted the source for the data and found out that this means "variable direction." Knowing that your friend will have the same question, use the dfWeather.apply() method to change all instances of "VRB" to "Variable Direction" in that HOURLYWindDirection column.
- HINT: The function to which your dfWeather.apply() refers must return some value every time it is called, otherwise the column values will be replaced with None, which means a null value.
- You need to save the cleansed data in computer-file format so that you can email it to your friend. You discover a pandas method that you can use to save the contents of the revised DataFrame. You implement it like this to save a file named newWeather.csv with this command: dfWeather.to_csv('newWeather.csv',index=False)
What I have so far:
import pandas as pd #importing csv file using relative reference dfWeather = pd.read_csv('WburgWeather.csv') print('Type of df variable:', type(dfWeather)) print('Column Labels:', dfWeather.columns.values) #converting column names from F to C dfWeather.rename(columns ={'HOURLYDRYBULBTEMPF':'HOURLYDRYBULBTEMPC', 'HOURLYWETBULBTEMPF':'HOURLYWETBULBC', 'HOURLYDewPointTempF':'HOURLYDewPointTempC'}, inplace = True) #removing column that has no data dfWeather.drop('HOURLYPRSENTWEATHERTYPE', axis = 1, inplace = True) print('Column Labels:', dfWeather.columns.values)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started