Question
here's my code import pandas as pd base_path_file = 'path_where_file_is_present' dataset = pd.DataFrame(pd.read_csv(base_path_file + 'SunSpot.csv')) cols = ['Year', 'Month', 'Day', 'NUmberOfSunspots'] data = [] #
here's my code
import pandas as pd
base_path_file = 'path_where_file_is_present'
dataset = pd.DataFrame(pd.read_csv(base_path_file + '\SunSpot.csv'))
cols = ['Year', 'Month', 'Day', 'NUmberOfSunspots']
data = []
# Refining dataset
for value in dataset.values:
try:
data.append([value[0], value[1], value[2],
value[3], int(value[4]), value[5]])
except ValueError:
data.append([value[0], value[1], value[2], value[3], 0, value[5]])
monthData = {}
for value in data:
year_month_combination = str(value[0]) + '_' + str(value[1])
try:
monthData[year_month_combination] += 1
except KeyError:
monthData[year_month_combination] = 1
monthDataList = []
for key in monthData.keys():
monthDataList.append(
[key.split('_')[0], key.split('_')[1], monthData[key]])
df = pd.DataFrame(monthDataList, columns=[
'Year', 'Month', 'Number Of Sunspots'])
df.to_csv(base_path_file + '\Monthtotal.csv')
def smoothValue(l: list):
list_length = len(l)
if list_length == 0:
return 0
sum = 0
for value in l:
sum += value[2]
sum -= (l[0][2] / 2 + l[list_length - 1][2] / 2)
return sum / list_length
smoothed_list = []
count = 0
for l in monthDataList:
startIndex = 0
endIndex = 0
if (count - 6
startIndex = 0
else:
startIndex = count - 6
if count + 6 > len(monthDataList) - 1:
endIndex = len(monthDataList) - 1
else:
endIndex = count + 6
smoothed_list.append([l[0], l[1], smoothValue(
monthDataList[startIndex:endIndex])])
count += 1
df = pd.DataFrame(smoothed_list, columns=[
'Year', 'Month', 'Number Of Sunspots'])
df.to_csv(base_path_file + '\MonthSmoothed.csv')
sun spcts 2.py File Edit Forrmat Run Options Window Help import pandas aa pa n spcts 2.py (7.0) base path rile'pahwhere ile 15_present dataset pd.DataFrane (pd.read cv (base path_file Sunspot.c' data [ fox value in dataset-values: data.append (tvalue [0], valaue[i value[2] excopr ValueError: data . append { [value [ 0] , value [ 1 ] , value l 2 value 13] 0, value [ S11 } monthData or value in data: year monch combinarionar (valuetoj+'_' +atx alueti EY: monthDatayear month_cmbination1 xcept KeyErrori monthDatayear monh_cmbinatin1 monthDataList - monthDstaList.sppend rkey.split('101, Icey.sp11-')[11, monthDataney11) dfpd.Dataframe (mon hDatalia, colunna- Ln: 100 Cot0 918 PM Type here to search sun spcts 2.py File Edit Forrmat Run Options Window Help import pandas aa pa n spcts 2.py (7.0) base path rile'pahwhere ile 15_present dataset pd.DataFrane (pd.read cv (base path_file Sunspot.c' data [ fox value in dataset-values: data.append (tvalue [0], valaue[i value[2] excopr ValueError: data . append { [value [ 0] , value [ 1 ] , value l 2 value 13] 0, value [ S11 } monthData or value in data: year monch combinarionar (valuetoj+'_' +atx alueti EY: monthDatayear month_cmbination1 xcept KeyErrori monthDatayear monh_cmbinatin1 monthDataList - monthDstaList.sppend rkey.split('101, Icey.sp11-')[11, monthDataney11) dfpd.Dataframe (mon hDatalia, colunna- Ln: 100 Cot0 918 PM Type here to search
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