About 633,000 results
Open links in new tab
  1. How to read CSV file in Python? - Stack Overflow

    May 15, 2016 · def read_csv(csv_file): data = [] with open(csv_file, 'r') as f: # create a list of rows in the CSV file rows = f.readlines() # strip white-space and newlines rows = list(map(lambda x:x.strip(), rows)) for row in rows: # further split each row into columns assuming delimiter is comma row = row.split(',') # append to data-frame our new row ...

  2. Why does my Python code print the extra characters "" when …

    Dec 21, 2015 · Note that if you're on Python 2, you should see e.g. Python, Encoding output to UTF-8 and Convert UTF-8 with BOM to UTF-8 with no BOM in Python. You'll need to do some shenanigans with codecs or with str.decode for this to work right in Python 2. But in Python 3, all you need to do is set the encoding= parameter when you open the file.

  3. python - How to import a csv-file into a data array ... - Stack …

    Oct 7, 2017 · You can use pandas library or numpy to read the CSV file. If your file is tab-separated then use '\t' in place of comma in both sep and delimiter arguments below. import pandas as pd myFile = pd.read_csv('filepath', sep=',') Or . import numpy as np myFile = np.genfromtxt('filepath', delimiter=',')

  4. Importing csv from a subdirectory in Python - Stack Overflow

    Apr 19, 2012 · Another common trap with windows paths is that using backslashes escape characters, so you must escape your backslashes ("some\\file") - an ugly option, use raw strings (r"some\file"), use forward slashes (Python will actually handle this automatically), or - the best option, pass your path as arguments to the aforementioned os.path.join().

  5. python - Best way to convert csv data to dictionaries - Stack …

    Notice that you can explicitly pass the headers which you want to be the keys, making it very easy to use csv files without headers. Another use case is reading just a regular string with csv, for example: import csv my_csv_string = 'val1, val2, val3' my_csv_dict = next(csv.DictReader(StringIO(s), fieldnames=('key1', 'key2', 'key3'))) Anyway ...

  6. python - Import CSV file as a Pandas DataFrame - Stack Overflow

    To read a CSV file as a pandas DataFrame, you'll need to use pd.read_csv, which has sep=',' as the default.. But this isn't where the story ends; data exists in many different formats and is stored in different ways so you will often need to pass additional parameters to read_csv to ensure your data is read in properly.

  7. Reading rows from a CSV file in Python - Stack Overflow

    I have a CSV file, here is a sample of what it looks like: Year: Dec: Jan: 1 50 60 2 25 50 3 30 30 4 40 20 5 10 10 I know how to read the file in and print each

  8. python - Read CSV or Excel - Stack Overflow

    If pd.read_csv() is first in the try/except block and I upload a .csv file it works. If I attempt to upload a .xlsx file, I get this error: TypeError: expected str, bytes or os.PathLike object, not NoneType If pd.read_excel() is first in the try/except block and I upload an .xlsx file it works. If I attempt to upload a .csv file, I get this error:

  9. How to read a csv file from an s3 bucket using Pandas in Python

    Jun 13, 2015 · def read_file(bucket_name,region, remote_file_name, aws_access_key_id, aws_secret_access_key): # reads a csv from AWS # first you stablish connection with your passwords and region id conn = boto.s3.connect_to_region( region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key) …

  10. Opening a CSV from a Different Directory Python

    The tilde tells me that this is the home folder (e.g. C:\Users\<username> on my Windows system, or /Users/<username> on my Mac).

Refresh