In: Computer Science
# importing the module
import pandas as pd
# creating the DataFrame
marks_data = pd.DataFrame({'ID': {0: 23, 1: 43, 2: 12,
3: 13, 4: 67, 5: 89,
6: 90, 7: 56, 8: 34},
'Name': {0: 'Ram', 1: 'Deep',
2: 'Yash', 3: 'Aman',
4: 'Arjun', 5: 'Aditya',
6: 'Divya', 7: 'Chalsea',
8: 'Akash' },
'Marks': {0: 89, 1: 97, 2: 45, 3: 78,
4: 56, 5: 76, 6: 100, 7: 87,
8: 81},
'Grade': {0: 'B', 1: 'A', 2: 'F', 3: 'C',
4: 'E', 5: 'C', 6: 'A', 7: 'B',
8: 'B'}})
# determining the name of the file
file_name = 'MarksData.xlsx'
# saving the excel
marks_data.to_excel(file_name)
print('DataFrame is written to Excel File successfully.')
Explanation:
1. For this task you need to install a librabry pandas of python.
2. DataFrame is data structure, that we have used it is present in pandas.
3. here we have created 4 colums(ID, Name, Marks and Grade).
4. row and there values are stores in dictionary as key value pairs.
5. filename stores the name of the file that we want to save these datas in.
6. to_excel() is a method in pandas that wites data in excelsheet.
I have attached the screenshot of compiler for your better understanding.
If you have any doubt feel free to ask in below comments. Thank You.