Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a folder of CSV files that I need to edit. Each file has a blank line in the middle. I want to take everything under that blank line and put it into a new excel sheet while rewriting my CSV file to a xls file. How can I do this?
A quick Google search revealed the openpyxl library that you can use to create XLS files.
Reading CSV is built into Python.
The rest is a simple matter of programming :) If you run into a more specific problem, please feel free to post a new question.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 months ago.
Improve this question
I have two excel files with multiple sheets in it, I want to import one sheet from the second excel file to first excel file as new sheet programmatically. While importing I want to retain formatting of the sheet
Looking solution in Python or PowerShell. Didn’t find anything in the search, hence posting this question.
Thanks
Very basic boilerplate Powershell script ...
$excelApplication = New-Object -comobject Excel.Application
$sourceWorkbook = $excelApplication.Workbooks.Open("C:\temp\Source.xlsx")
$sourceWorksheet = $sourceWorkbook.Worksheets("Sheet1")
$destinationWorkbook = $excelApplication.Workbooks.Open("C:\temp\Destination.xlsx")
$sourceWorksheet.Copy($destinationWorkbook.Sheets(1))
$destinationWorkbook.Save()
$excelApplication.Quit()
It will need work to make it perfect but it's something to run with.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 months ago.
Improve this question
When I open and excel file, the excel show me a message.
"Do you want to open this excel file anyway?" Yes, No, Cancel
I want to open it by python and automatically click Yes by python too, afterr that I will start to edit the excel by python program. I don't know what to do with pushing the yes button! I am totally beginner in python. I would be grateful if anyone can help me.
The Python module pandas can help you. If you change the file extension to .xlsx as pyzer mentioned, you can access your data with pandas as explained in this tutorial.
For a few general resources on learning Python, I recommend the official documentation and The Hitchiker's Guide to Python.
Best of luck!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have trouble reading this csv file downloaded from kaggle. I have tried using the utf-8 encoding and it was still not able to read the csv file
There might be some special characters in the file.
import pandas as pd
df = pd.read_csv(r"file_path", encoding="latin1")
with open('filename.csv') as file_info:
print(file_info)
The encoding will be at the end.
data=pd.read_csv('filename.csv', encoding="encoding from file_info")
Works every time.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need to program a script in python that writes an excel file with three categories and it's input being three text files.
It would be much appreciated if you could help me out because I have literally no idea how to work with excel files.
Thanks in advance!
A reasonable path to follow when processing Excel with Python is Pandas' dataframe. You can get started with reading some documentation from them and get experimenting with it.,
pip install pandas
import pandas as pd
df = pd.read_excel("path_to_file.xls", sheet_name="Sheet1")
df.to_excel(filepath, sheet_name='Sheet1')
Starting from here you can do a lot with pandas and excel
I see people recommending xlwt. XLWT keeps formats for excel and does styling which is another reasonable path, but in comparason lacks some functionaility when processing datas. In either cases, both only supports legacy (pre-2007 for Pandas and pre-2003 for XLWT) verisons of Excel
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
In python, I want to open a file if already exists or create it if it doesnt exist. also i want to write to the file new contents on opening it without overwriting the existing contents of the file. How can I do it?
PEP8 suggests you to use:
with open('test.txt', 'a+') as f:
f.write( "Your new content" )
The with statement is better because it will ensure you always close the file, even if an exception is raised.
Example adapted from: http://docs.python-guide.org/en/latest/writing/style/#pep-8
You can use:
file = open('myfile.dat', 'a+')
Refer to this link for details:
http://docs.python.org/2/tutorial/inputoutput.html