4 examples of 'pandas read csv' in Python

Every line of 'pandas read csv' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
37def readcsv(filename, header=True):
38 return pd.read_csv(filename, header=None) if not header else pd.read_csv(filename)
63def _dataframe_from_csv(reader, delimiter, with_header, skipspace):
64 """Returns csv data as a pandas Dataframe object"""
65 sep = delimiter
66 header = 0
67 if not with_header:
68 header = None
69
70 return pd.read_csv(
71 reader,
72 header=header,
73 sep=sep,
74 skipinitialspace=skipspace,
75 encoding='utf-8-sig'
76 )
10def read_data():
11 '''
12 reads data from csv that I generated from copying and pasting articles from
13 5 different news sources
14 '''
15 wiki = pd.read_csv("data/wikipedia_data.csv")
16 fox = pd.read_csv("data/fox_data.csv")
17 npr = pd.read_csv("data/npr_data.csv")
18 cnn = pd.read_csv("data/cnn_data.csv")
19 cnn = cnn[cnn['text'].apply(str) != 'nan']
20 data = pd.concat((wiki[['source', 'text', 'rating']], fox[['source', 'text', 'rating']],
21 npr[['source', 'text', 'rating']], cnn[['source', 'text', 'rating']] ), ignore_index=True)
22 return data
554def _csv_to_pandas_df(filepath,
555 separator=DEFAULT_SEPARATOR,
556 quote_char=DEFAULT_QUOTE_CHARACTER,
557 escape_char=DEFAULT_ESCAPSE_CHAR,
558 contain_headers=True,
559 lines_to_skip=0,
560 date_columns=None,
561 rowIdAndVersionInIndex=True):
562 test_import_pandas()
563 import pandas as pd
564
565 # DATEs are stored in csv as unix timestamp in milliseconds
566 def datetime_millisecond_parser(milliseconds): return pd.to_datetime(milliseconds, unit='ms', utc=True)
567
568 if not date_columns:
569 date_columns = []
570
571 line_terminator = str(os.linesep)
572
573 df = pd.read_csv(filepath,
574 sep=separator,
575 lineterminator=line_terminator if len(line_terminator) == 1 else None,
576 quotechar=quote_char,
577 escapechar=escape_char,
578 header=0 if contain_headers else None,
579 skiprows=lines_to_skip,
580 parse_dates=date_columns,
581 date_parser=datetime_millisecond_parser)
582 if rowIdAndVersionInIndex and "ROW_ID" in df.columns and "ROW_VERSION" in df.columns:
583 # combine row-ids (in index) and row-versions (in column 0) to
584 # make new row labels consisting of the row id and version
585 # separated by a dash.
586 zip_args = [df["ROW_ID"], df["ROW_VERSION"]]
587 if "ROW_ETAG" in df.columns:
588 zip_args.append(df['ROW_ETAG'])
589
590 df.index = row_labels_from_id_and_version(zip(*zip_args))
591 del df["ROW_ID"]
592 del df["ROW_VERSION"]
593 if "ROW_ETAG" in df.columns:
594 del df['ROW_ETAG']
595
596 return df

Related snippets