Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

How to print to excel/csv?

$
0
0

Current task is to pull only numbers from a text file. I have this part working and it's printing vertically in the console.

I'm trying to print my output to an CSV or Excel file. Preferably to the same column. Can I just replace my print line with f.save()?

import re
import xlwt

f = open('printouthg.csv','w')


file_name = r'C:\Users\hank\desktop\pycodes\numbers.txt'
with open(file_name, 'r') as file:
    filedata = file.read()

lines = filedata
import re
output = []
repl_str = re.compile('\d+.?\d*')
#t = r'\d+.?\d*'
line = lines.split()
for word in line:
    match = re.search(repl_str, word)
    if match:
        output.append(float(match.group()))

print(*output, sep='\n')

Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>