Created
January 27, 2020 14:25
-
-
Save fabsta/12728458615d338366aae53b7bc11bc5 to your computer and use it in GitHub Desktop.
[pandas read csv] read in a csv file #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# often works | |
df = pd.read_csv('file.csv') | |
df = pd.read_csv('file.csv', header=0, index_col=0, quotechar='"',sep=':', na_values = ['na', '-', '.', '']) | |
# specifying "." and "NA" as missing values in the Last Name column and "." as missing values in Pre-Test Score column | |
df = pd.read_csv('../data/example.csv', na_values={'Last Name': ['.', 'NA'], 'Pre-Test Score': ['.']}) | |
# skipping the top 3 rows | |
df = pd.read_csv('../data/example.csv', na_values=sentinels, skiprows=3) | |
# interpreting "," in strings around numbers as thousands separators | |
df = pd.read_csv('../data/example.csv', thousands=',') | |
# `encoding='latin1'`, `encoding='iso-8859-1'` or `encoding='cp1252'` | |
df = pd.read_csv('example.csv',encoding='latin1') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment