Question
I have created this: hornets_stats=[] with open (charlotte_hornets_stats.txt, r) as f: for line in f: player_stats=line.strip().split('#') hornets_stats.append(player_stats) It prints this: print('PART A') print('STEPS 1-5 -
I have created this:
hornets_stats=[] with open ("charlotte_hornets_stats.txt", "r") as f: for line in f: player_stats=line.strip().split('#') hornets_stats.append(player_stats)
It prints this:
print('PART A') print('STEPS 1-5 - hornets_stats LIST') print(f'Lines in hornets_stats = {len(hornets_stats)} ') # Print each line in hornets_stats list for line in hornets_stats: print(line)
PART A STEPS 1-5 - hornets_stats LIST Lines in hornets_stats = 18 ['NAME ', 'POS', 'GP', 'GS', 'MIN', 'PTS', 'OR', 'DR', 'REB', 'AST', 'STL', 'BLK', 'TO', 'PF', 'AST/TO'] ['P.J. Washington ', 'PF ', '59', '59', '32.9', '15.2', '1.0', '3.7', '4.7', '2.4', '0.9', '1.1', '1.4', '2.6', '1.7'] ['Mason Plumlee ', 'C ', '56', '56', '28.5', '12.2', '3.3', '6.3', '9.7', '3.7', '0.6', '0.6', '1.6', '2.9', '2.4'] ['Jalen McDaniels ', 'PF ', '56', '21', '26.7', '10.6', '0.8', '4.0', '4.8', '2.0', '1.2', '0.5', '1.4', '2.8', '1.4'] ['Terry Rozier ', 'SG ', '49', '49', '35.6', '21.8', '1.0', '3.3', '4.3', '4.9', '1.1', '0.3', '2.1', '1.9', '2.3'] ['JT Thor ', 'F ', '47', '0', '10.8', '2.6', '0.5', '1.2', '1.7', '0.4', '0.2', '0.2', '0.5', '0.8', '0.8'] ['Nick Richards ', 'C ', '45', '0', '17.3', '8.0', '2.5', '3.3', '5.8', '0.5', '0.2', '1.0', '0.9', '2.3', '0.6'] ['Dennis Smith Jr. ', 'PG ', '38', '12', '25.0', '8.4', '0.4', '2.3', '2.8', '4.4', '1.4', '0.4', '1.6', '2.2', '2.8'] ['Theo Maledon ', 'PG ', '36', '1', '16.1', '5.6', '0.3', '2.1', '2.4', '2.4', '0.8', '0.2', '1.0', '1.0', '2.5'] ['Kelly Oubre Jr. ', 'SG ', '35', '30', '32.6', '20.2', '1.5', '3.6', '5.1', '1.2', '1.6', '0.4', '1.3', '3.0', '1.0'] ['Gordon Hayward ', 'SF ', '34', '34', '31.1', '13.9', '0.7', '3.5', '4.2', '3.6', '0.9', '0.2', '1.9', '1.3', '2.0'] ['LaMelo Ball ', 'PG ', '33', '33', '35.4', '23.3', '1.2', '5.1', '6.3', '8.4', '1.3', '0.3', '3.5', '3.4', '2.4'] ['Mark Williams ', 'C ', '29', '4', '15.9', '7.6', '1.7', '3.9', '5.6', '0.3', '0.7', '1.2', '0.8', '2.1', '0.4'] ['Kai Jones ', 'PF ', '27', '0', '8.8', '2.7', '0.7', '1.2', '1.9', '0.2', '0.2', '0.4', '0.3', '1.1', '0.6'] ['James Bouknight ', 'SG ', '26', '0', '13.6', '4.3', '0.2', '1.8', '2.0', '1.1', '0.5', '0.2', '0.7', '1.1', '1.5'] ['Bryce McGowens ', 'G ', '26', '1', '14.7', '4.1', '0.3', '1.3', '1.7', '1.0', '0.3', '0.2', '0.6', '0.8', '1.8'] ['Cody Martin ', 'SF ', '7', '0', '19.1', '5.0', '1.1', '2.3', '3.4', '1.6', '0.6', '0.1', '0.3', '1.9', '5.5'] ['Svi Mykhailiuk ', 'SG ', '1', '0', '25.0', '12.0', '1.0', '1.0', '2.0', '0.0', '0.0', '0.0', '1.0', '1.0', '0.0']
I NOW NEED TO DO THIS WITH THE DATA!
1. Open a file named charlotte_hornets_stats.csv using with open() as file 2. Use csv.writer(...) to get a "writer object" 3. Iterate thru the hornets_stats list using .writerow(...) to create the new CSV file named charlotte_hornets_stats.csv -- REMINDER: Make sure you specify the correct delimiter for a CSV file!
4. Open the newly created file named charlotte_hornets_stats.csv using with open() as file, then: 5. Use csv.reader(...) to get a "reader object" 6. Use a FOR-loop to iterate thru each row/line of the file and print the row/line.
7. Add the required import statement for pandas 8. Read file charlotte_hornets_stats.csv using Pandas read_csv(...) function. 9. Save the file contents in a DataFrame named hornets_df 10. Print the DataFrame hornets_df
***I KNOW THAT YOU CANNOT GIVE EXACT BECAUSE YOU DO NOT HAVE ALL THE FILES BUT CODE IS REALLY WHAT I NEED HELP WITH***
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