Print Column Indices from CSV File in Python with Visual Studio Code on Windows - DevPops-Inc/python GitHub Wiki
• Press the Windows key, type “visual studio code” and select “Open.”
•
• Press the Ctrl and N key to create a new file.
•
• Select “Select a Language.”
•
• Type “python” in the search box and select “Python (python)” from the result.
•
• Type import pandas as pd
and press the Enter key to import the Pandas module as the pd
variable.
•
• Type from openpyxl.workbook import Workbook
and press the Enter key twice to import the Workbook
object from the openpyxl.workbook module
.
•
• Type df = pd.read_csv(‘< filename >.csv’, header=None)
and press the Enter key to declare the df
variable and set it to read the .csv file without headers.
•
• Type df.columns = [‘< column 1 >, ‘< column 2 >’, ‘< . . . >’]
and press the Enter</kbd key twice to define the list of columns.
•
• Type print(df.columns)
to print the columns in the TERMINAL.
•
• Press the Ctrl and S keys to save.
•
• Browse to the desired location, type the filename in the “File name:” box then select “Save.”
•
• Press the Run button to run the Python script.
•
• The columns will print in the TERMINAL.
•
• Type clear
and press the Enter key to clear the TERMINAL.
•
• Return to the editor, replace .columns
in print(df.columns)
with [‘< column >’, ‘< indices >’]
and press the Run button to print the desired column and indices.
•
• The column and indices will print in the TERMINAL.
•