# import libraries import pandas as pd from pandas import ExcelWriter import os # function to get data. def get_data (): warnings = open ( ’ warnings.txt’ , ’r’ ) suggestions = open ( ’suggestions.txt’ , ’r’ ) packages = open ( ’packages.txt’ , ’ r’ ) shells = open ( ’shells.txt’ , ’ r’ ) warn_data = warnings.readlines () sugg_data = suggestions.readlines () pack_dat a = packages.read () shell_data = shells.readlines () return warn_data, sugg_data, pack_data, shell_data def clean_data (): warn, sugg, pack, shell = get_data () warn_clean = [] for line in warn: warn_clean.append (line.split ( ’|’ )) for i in range ( len (warn_clean)): warn_clean [i] = warn_clean [i] [: 2 ] # print (warn_clean [i]) sugg_clean = [] for line in sugg: sugg_clean.append (line.split ( ’|’ )) for i in range ( len (sugg_clean)): sugg_clean [i] = sugg_clean [i] [: 2 ] # print (sugg_clean [i]) pack_clean = [] pack = pack.split ( ’|’ ) pack_clean = pack del pack_clean [ 0 ] shell_clean = [] for i in range ( len (shell)): shell_clean.append (shell [i] .rstrip ( ’’ )) # print (shell_clean [i]) return warn_clean, sugg_clean, pack_clean, shell_clean def convert_to_excel (): warnings, suggestions, packages , shells = clean_data () try : os.mkdir ( ’outputs’ ) except (Exception): pass os.chdir ( ’ outputs’ ) warn_packages = [] warn_text = [] for i in range ( len (w arnings)): warn_packages.append (warnings [i] [ 0 ]) for i in range ( len (warnings)): warn_text.append (warnings [i] [ 1 ]) print (warn_packages, warn_text) warn = pd.DataFrame () warn [ ’Packages’ ] = warn_packages warn [ ’warnings’ ] = warn_text # warn.to_excel (& # 39; warnings.xlsx & # 39 ;, index = False) writer = ExcelWriter ( ’warnings.xlsx’ ) warn.to_excel (writer, ’ report1’ , index = False ) workbook = writer.book worksheet = writer. sheets [ ’report1’ ] # Invoice information columns worksheet.set_column ( ’A: A’ , 15 ) # State column worksheet.set_column ( ’B: B’ , 45 ) # Zip code # worksheet.set_column (& # 39; F: F & # 39 ;, 10) writer.save () sugg_packages = [] sugg_text = [] for i in range ( len (suggestions)): sugg_packages.append (suggestions [i] [ 0 ]) for i in range ( len (suggestions)): sugg_text.append (suggestions [i] [ 1 ]) # print (sugg_packages, sugg_text) suggestive = pd.DataFrame () sugg [ ’Packages’ ] = sugg_packages [ ’suggestions’ ] = sugg_text writer1 = ExcelWriter ( ’suggestions.xlsx’ ) sugg.to_excel (writer1, ’report2’ , index = False ) workbook = writer1.book worksheet = writer1.sheets [ ’report2’ ] # Invoice information columns worksheet.set_column ( ’A: A’ , 25 ) # State column worksheet.set_column ( ’B: B’ , 120 ) # Postal code # worksheet.set_column (& # 39; F: F & # 39 ;, 10) writer1.save () pack_data = pd.DataFrame () pack_data [ ’ Packages’ ] = packages writer1 = ExcelWriter ( ’ packages.xlsx’ ) pack_data.to_excel (writer1, ’report3’ , index = False ) workbook = writer1.book worksheet = writer1 .sheets [ ’report2’ ] # Invoice information columns worksheet.set_column ( ’A: A’ , 25 ) # State column worksheet.set_column ( ’B: B’ , 120 ) # Zip code # worksheet.set_column (& # 39; F: F & # 39 ;, 10) writer1.save () Python | System Gain and Compliance Reports Using Lynis __del__: Questions
How can I make a time delay in Python?
5 answers
I would like to know how to put a time delay in a Python script.
2973
Answer #1
import time
time.sleep(5) # Delays for 5 seconds. You can also use a float value.
Here is another example where something is run approximately once a minute:
import time
while True:
print("This prints once a minute.")
time.sleep(60) # Delay for 1 minute (60 seconds).
Python | System Gain and Compliance Reports Using Lynis __del__: Questions
How to delete a file or folder in Python?
5 answers
How do I delete a file or folder in Python?
2639
Answer #1
Path objects from the Python 3.4+ pathlib module also expose these instance methods:
Shop
Best Python online courses for 2022 $FREE
Best laptop for Excel $
Best laptop for Solidworks $399+
Best laptop for Roblox $399+
Best computer for crypto mining $499+
Best laptop for Sims 4 $
Best laptop for Zoom $499
Best laptop for Minecraft $590
Latest questions
PythonStackOverflow
Common xlabel/ylabel for matplotlib subplots
1947 answers
PythonStackOverflow
Check if one list is a subset of another in Python
1173 answers
PythonStackOverflow
How to specify multiple return types using type-hints
1002 answers
PythonStackOverflow
Printing words vertically in Python
909 answers
PythonStackOverflow
Python Extract words from a given string
798 answers
PythonStackOverflow
Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?
606 answers
PythonStackOverflow
Python os.path.join () method
384 answers
PythonStackOverflow
Flake8: Ignore specific warning for entire file
360 answers
Wiki
Python | How to copy data from one Excel sheet to another
Common xlabel/ylabel for matplotlib subplots
Check if one list is a subset of another in Python
How to specify multiple return types using type-hints
Printing words vertically in Python
Python Extract words from a given string
Cyclic redundancy check in Python
Finding mean, median, mode in Python without libraries
Python add suffix / add prefix to strings in a list
Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?
Python - Move item to the end of the list
Python - Print list vertically
|