13 data.frame & DataFrame

  • Set the current working directory to read the data file
  • Check all objects in the current working directory
  • R base format of data is data.frame
  • In Python, we need to load pandas library

13.1 R

  • The R object of representing data in rows and columns is data.frame

  • The data.frame object is included with base R

  • This section sets the working directory where a csv file is located and read the data from the location in R environment

Function Explanation Example
setwd Set the working directory setwd(Path/to/folder)
getwd Get the current working directory getwd()
dir List files in a directory dir()
ls List all objects loaded in the global environment ls()
rm Remove an object from the global environment rm(obj_name)
read.table Read a tabular data - it reads tabular data with field names and specific delimiter read.table(Path/to/folder/file_name.txt)
read.csv Read a CSV file read.csv(Path/to/folder/file_name.csv)

13.2 Python

  • We need to load pandas library which will allow access Python object DataFrame

  • pandas is a flexible and easy data analysis and manipulation tool in Python

  • This section sets the working directory where a csv file is located and read the data from the location in Python environment

  • Check (pandas website)[https://pandas.pydata.org/] for further details


import os

import pandas as pd

Function Explanation Example
chwd Function from the os library to set (check) into the working directory os.chdir('Path/to/folder')
getcwd Function from the os library to get the current working directory os.getcwd()
listdir List files in a directory os.listdir()
globals List all objects loaded in the global environment globals()
del Remove an object from the global environment del(obj_name)
read_csv Function from the pandas library to read tabular data with delimiter pd.read_csv('Path/to/folder/file_name.txt', delimiter = '\t')
read_csv Function from the pandas library to read CSV data pd.read_csv('Path/to/folder/file_name.csv')