Importing a CSV Into Pandas
Import necessary modules
import pandas as pd
import numpy as np
Create a toy dataframe (to be converted into csv)
data = {'name':['Ernest', 'Jason', 'Kevin', 'Christine'],
'job':['Analyst', 'Nerd', 'Teacher', 'Product Manager'],
'salary':['$60,000','','$70,000','$80,000']}
df = pd.DataFrame(data,columns = ['name','job','salary'])
df
name | job | salary | |
---|---|---|---|
0 | Ernest | Analyst | $60,000 |
1 | Jason | Nerd | |
2 | Kevin | Teacher | $70,000 |
3 | Christine | Product Manager | $80,000 |
Export the dataframe to a csv in the current directory
df.to_csv('career_info.csv')
Now, load the csv
df = pd.read_csv('career_info.csv')
df
Unnamed: 0 | name | job | salary | |
---|---|---|---|---|
0 | 0 | Ernest | Analyst | $60,000 |
1 | 1 | Jason | Nerd | NaN |
2 | 2 | Kevin | Teacher | $70,000 |
3 | 3 | Christine | Product Manager | $80,000 |
Notice Pandas conveniently pulls in the header information without needing specification