Question

In: Computer Science

how to export source data to excel file in python?

how to export source data to excel file in python?

Solutions

Expert Solution

# 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.


Related Solutions

Python 3 Code does not save properly the data in the excel file. it stores the...
Python 3 Code does not save properly the data in the excel file. it stores the data in the same row over and over # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money...
I have an excel file imported into canopy (python) using import pandas as pd. The excel...
I have an excel file imported into canopy (python) using import pandas as pd. The excel file has headers titled: datetime created_at PM25 temperatureF dewpointF    humidityPCNT windMPH    wind_speedMPH wind_gustsMPH pressureIN precipIN these column headers all have thousands of data numbers under them. How could i find the average of all of the numbers in each column and plot them on 1 graph (line graph or scatter plot) Thank you.(please comment out your code)
In the Excel data file, the tab labeled Question 1 contains data on the number of...
In the Excel data file, the tab labeled Question 1 contains data on the number of times boys and girls raise their hands in class. Conduct the t-test: Two-Sample Assuming Equal Variances. Males 9,8,4,9,3,8,10,8,9,10,7,6,12 Females 3,5,1,2,6,4,3,6,7,9,7,3,7,6,8,8 a. What is the null hypothesis? b. What is the research hypothesis? c. Why run a Two-Sample Assuming Equal Variances t-test? d. Interpret the findings. What are the results of the hypothesis test? Can you reject the null hypothesis?
Describe how to open a file in Excel? What is the difference between opening a file...
Describe how to open a file in Excel? What is the difference between opening a file and creating a new file in Excel?
The data set for this question set (Tab Q1 in the Excel data file) comes from...
The data set for this question set (Tab Q1 in the Excel data file) comes from a research project that tracks the elderly residents in a community to monitor their cognitive function and general health. Based on the literature, education is considered a protective factor against dementia, and memory decline is usually the first sign of dementia. So the researchers would like to know whether education level (measured in number of years of formal schooling) is correlated with memory function...
Enter the Shoe Size and Height data from the In class data Excel file (use the...
Enter the Shoe Size and Height data from the In class data Excel file (use the excel in class data lab file loaded into the files section of Canvas) into the week 7 Regression Excel sheet. Create a scatter plot for the data, store and graph the regression equation, and note the r2 and r value. Looking at the graph and the r, and r^2 value, do you feel that shoe size is a good predictor for height? Explain your...
Python 3 Fix the code. It is not saving the data into the xls file Code:...
Python 3 Fix the code. It is not saving the data into the xls file Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Working product").grid(row=4, sticky="W", pady=20, padx=20) #Working product label tk.Label(window, text="Failed...
Refer to the data in the Excel (College) File. a) Construct a crosstabulation with Year Founded...
Refer to the data in the Excel (College) File. a) Construct a crosstabulation with Year Founded as the row variable and %Graduate as the column variable. Use classes starting with 1600 and ending with 2000 in increments of 50 for Year Founded. For % Graduate, use classes starting with 35% and ending with 100% in increments of 5%. b) Compute the row percentages for your crosstabulation in part (a). c) Construct a scatter diagram to show the relationship between Tuition&Fees...
For the data in the Excel file Education and Income, find 95% confidence intervals for the...
For the data in the Excel file Education and Income, find 95% confidence intervals for the mean annual income of males and the mean annual income of females. Can you conclude that the mean income of one group is larger than the other? Education and Income Gender Age Level of Education Gross Annual Income Female 40-60 Graduate Degree $75,000 Female 25-39 Bachelor's Degree $47,000 Male 40-60 High School/GED $40,000 Female 25-39 Some College $30,000 Female 25-39 Some College $60,000 Female...
A cost estimator for a construction company has collected the data found in the source file...
A cost estimator for a construction company has collected the data found in the source file Estimation.xlsx describing the total cost (Y) of 97 difference projects and the following 3 independent variables thought to exert relevant influence on the total cost: total units of work required (X1), contracted units of work per day (X2), and city/location of work (X3). The cost estimator would like to develop a regression model to predict the total cost of a project as a function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT