Python hand play (get column names from CSV file)

What is this article?

As the title says. An article like I wrote in 10 minutes. Take the first line of the CSV file and split (',') and return it. that's all.

Foreshadowing ... maybe?

code



def get_lines_from_textfile(filepath):
    with open(filepath, 'r', encoding='utf-8') as f:
        lines = f.readlines()
    return lines


def get_columns_list(csvpath):
    line_1st = get_lines_from_textfile(csvpath)[0]
    return line_1st.split(',')


def main():
    csvpath = 'solubility.test.csv'
    columns = get_columns_list(csvpath)
    for column in columns:
        print(column)


if __name__ == '__main__':
    main()

Impressions

nothing special.

Recommended Posts

Python hand play (get column names from CSV file)
Python hand play (let's get started with AtCoder?)
Read Python csv file
Python hand play (division)
Python hand play (two-dimensional list)
Download csv file with python
Get macro constants from C (++) header file (.h) in Python
Python hand play (argparse minimum code)
Execute Python script from batch file
Python hand play (Pandas / DataFrame beginning)
[Python] Write to csv file with Python
Get data from Quandl in Python
Output to csv file with Python
Get one column from DataFrame with DataFrame
Python CSV file reading and writing
Get upcoming weather from python weather api
Python hand play (CSV is applied with Pandas DataFrame, but only full-column Insert from CSV to DB?)
Python hand play (RDKit descriptor calculation: SDF to CSV using Pandas)
[Python] How to convert db file to csv
Get html from element with Python selenium
Get exchange rates from open exchange rates in Python
[Note] Get data from PostgreSQL with Python
Play audio files from Python with interrupts
Read CSV file with python (Download & parse CSV file)
Python hand play (descriptor calculation: serious version)
Get keystrokes from / dev / input (python evdev)
Get battery level from SwitchBot in Python
Create a deb file from a python package
Python> Output numbers from 1 to 100, 501 to 600> For csv
[Python] Get the character code of the file
[Python] Get the main color from the screenshot
Get metric history from MLflow in Python
Get time series data from k-db.com in Python
How to read a CSV file with Python 2/3
Csv output from Google search with [Python]! 【Easy】
[Python] Convert from DICOM to PNG or CSV
Import Excel file from Python (register to DB)
From file to graph drawing in Python. Elementary elementary
Python hand play (one line notation of if)
Writing logs to CSV file (Python, C language)
Generate an insert statement from CSV with Python.
I tried reading a CSV file using Python
Transpose CSV file in Python Part 2: Performance measurement
Draw a graph with matplotlib from a csv file
Run a Python file from html using Django
[Python] Get one year's message history from Slack
Read line by line from a file with Python
Make JSON into CSV with Python from Splunk
Get only articles from web pages in Python
Speed evaluation of CSV file output in Python
Get the update date of the Python memo file.
Python2 / numpy> Replace only a specific column in a file with column data from another file> numpy.c_