Read data from CSV into Pandas. Output data from Pandas to CSV

Pandas
import pandas as pd
import numpy as np

  create dummy dataframe

raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 19, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70]}
df = pd.DataFrame(raw_data, columns = ['name', 'age', 'favorite_color', 'grade'])
df
name age favorite_color grade
0 Willard Morris 20 blue 88
1 Al Jennings 19 red 92
2 Omar Mullins 22 yellow 95
3 Spencer McDaniel 21 green 70

 

save dataframe as csv

df.to_csv('../students.csv')

 

load dataframe in from csv

df = pd.read_csv('../students.csv')
df.head()
Unnamed: 0 name age favorite_color grade
0 0 Willard Morris 20 blue 88
1 1 Al Jennings 19 red 92
2 2 Omar Mullins 22 yellow 95
3 3 Spencer McDaniel 21 green 70