CSV Files in Python || Python Tutorial || Learn Python Programming

Python

Video is ready, Click Here to View ×


Working with CSV files is simple in Python. Today we will introduce the CSV module and show you how to read and write CSV files. As a demo, we will analyze the first ten years of stock data for Google.

You can download a CSV containing the first 10 years of Google stock data here: https://goo.gl/3zaUlD

➢➢➢➢➢➢➢➢➢➢
To learn Python, you can watch our playlist from the beginning:…

46 thoughts on “CSV Files in Python || Python Tutorial || Learn Python Programming

  1. Traceback (most recent call last):
    File "E:/STUDY/siraj/csvPython..py", line 10, in <module>
    date = datetime.strptime(row[0], '%m/%d/%y')
    File "C:UsersPikesAppDataLocalProgramsPythonPython36-32lib_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
    File "C:UsersPikesAppDataLocalProgramsPythonPython36-32lib_strptime.py", line 365, in _strptime
    data_string[found.end():])
    ValueError: unconverted data remains: 14

    help me with that

  2. A big thanks for these great Python tutorials Socratica…..I'm learning a lot so far and just ran into my first issue. While using Python 3.6 when I do print(dir(csv)) I have no reader or writer attributes (see below), which makes using the code in the video generate an error….any ideas? Thanks again and cheers! 🙂

    ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'csv']

    AttributeError: module 'csv' has no attribute 'reader'

  3. Hi, My data is bit different format. When I used your methods, it is unable to separates my data. It is unable to break the data after each space. Look my data and code.

    import csv

    with open('main.txt', newline='') as f:

    reader = csv.reader(f)

    header_line_1 = next(reader)

    header_line_2 = next(reader)

    print(header_line_2)

    data = []

    for row in reader:

    data.append(row)

    Data is as followed.

    Theta [deg.] Phi [deg.] Abs(Dir.)[dBi ] Abs(??? )[dBi ] Phase(??? )[deg.] Abs(??? )[dBi ] Phase(??? )[deg.] Ax.Ratio[dB ]

    ——————————————————————————————————————————————————

    0.000 0.000 4.864e+00 4.864e+00 0.000 4.864e+00 0.000 -1.843e+01

    5.000 0.000 4.761e+00 4.761e+00 0.000 4.761e+00 0.000 -1.864e+01

    10.000 0.000 4.648e+00 4.648e+00 0.000 4.648e+00 0.000 -1.886e+01

    15.000 0.000 4.525e+00 4.525e+00 0.000 4.525e+00 0.000 -1.911e+01

    20.000 0.000 4.394e+00 4.394e+00 0.000 4.394e+00 0.000 -1.937e+01

    25.000 0.000 4.257e+00 4.257e+00 0.000 4.257e+00 0.000 -1.965e+01

    30.000 0.000 4.114e+00 4.114e+00 0.000 4.114e+00 0.000 -1.993e+01

    35.000 0.000 3.970e+00 3.970e+00 0.000 3.970e+00 0.000 -2.022e+01

    40.000 0.000 3.825e+00 3.825e+00 0.000 3.825e+00 0.000 -2.051e+01

  4. Please anyone help. I lost my password to my ETH wallet and am trying to install/run this python program. When I try to click on the downloaded file with the python icon, it opens then quickly closes. When I try to run the file through python ver 3.0 (command line), i keep getting errors. Am I doing something wrong or is the file corrupted? Please someone help me will give you some ETH if I succeed in cracking my wallet. Here is the python file: https://github.com/Isaacdelly/Plutus

  5. Oh god. Programmers and scientists must spend a quarter of their productive life importing and exporting CSV files to and from different languages or apps. There's got to be a better alternative to stupid, bloated CSV files for storing structured data, but the problem is that there are too many better alternatives. The solution? Export your data to a stupid CSV file.

  6. Great tutorials! Simple tip for accessibility: Avoid using the bottom 1/10th of the video window, as it will be covered by closed captions. With captions on, I can't see the code, arrows, and other content you're describing. Keeping content above the bottom 1/10th of the video window improves accessibility for users with hearing impairments and those who aren't fluent English speakers.

  7. i have a problem with python3.6
    my code:
    —path = '/Users/tobias/Desktop/google.csv'

    lines = [line for line in open(path, 'rb')]
    print(lines[0])—
    this can run but the output is garbled

    if i don't use 'rb' it give me a encode error like :

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xa9 in position 12: ordinal not in range(128)

  8. This is the first video I have watched of the python series and I am only 22 seconds in to the video. But, I feel like this video is a mission briefing in a video game cut scene. also, I am picking up a very seven of nine vibe. lol.

  9. how can i read a .txt file with a list like:
    juan
    pedro
    maria
    lola
    luis

    i need reed this file .txt from another file but read first the line1,then the line2,then the line 3 etc and when the last line come brake automatically

Leave a Reply

Your email address will not be published. Required fields are marked *