Skip to content

Instantly share code, notes, and snippets.

View Okorojeremiah's full-sized avatar
😃

Jeremiah Okoro Okorojeremiah

😃
  • Semicolon Africa
  • Lagos
  • 02:20 (UTC -12:00)
View GitHub Profile
@Okorojeremiah
Okorojeremiah / Opening, reading and extracting from a file
Created June 3, 2020 09:21
#write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: #X-DSPAM-Confidence: 0.8475 #Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a…
fname = input("Enter a file name:")
fh = open(fname)
count = 0
tot = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:"):
continue
fg = line.find("0")
ma = float(line[fg:])
count = count + 1
@Okorojeremiah
Okorojeremiah / flexing my data wrangling skills.csv
Created April 23, 2020 13:04
Created on Skills Network Labs
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 37 columns, instead of 10 in line 4.
,symboling,normalized-losses,make,num-of-doors,body-style,drive-wheels,engine-location,wheel-base,length,width,height,curb-weight,engine-type,num-of-cylinders,engine-size,fuel-system,bore,stroke,compression-ratio,horsepower,peak-rpm,city-mpg,highway-mpg,price,city-l/100km,horsepower-binned,diesel,gas,std,turbo,std,turbo,std,turbo,std,turbo
0,3,122,alfa-romero,two,convertible,rwd,front,88.6,0.8111484863046613,0.8902777777777777,0.8160535117056856,2548,dohc,four,130,mpfi,3.47,2.68,9.0,111,5000.0,21,27,13495.0,11.19047619047619,low,0,1,1,0,1,0,1,0,1,0
1,3,122,alfa-romero,two,convertible,rwd,front,88.6,0.8111484863046613,0.8902777777777777,0.8160535117056856,2548,dohc,four,130,mpfi,3.47,2.68,9.0,111,5000.0,21,27,16500.0,11.19047619047619,low,0,1,1,0,1,0,1,0,1,0
2,1,122,alfa-romero,two,hatchback,rwd,front,94.5,0.8226814031715521,0.9097222222222222,0.8762541806020067,2823,ohcv,six,152,mpfi,2.68,3.47,9.0,154,5000.0,19,26,16500.0,12.368421052631579,medium,0,1,1,0,1,0,1,0,1,0
3,2,164,audi,four,sedan,fwd,front,99.8,0.8