Python for R Users
Daniel Chen
Instructor
l = [0, 1, 2, 3, 4]
len(l) # call a function
l.len() # not a method
Periods have very specific meanings and uses
l = [1, "2", True]
l.append('appended value')
l
[1, '2', True, 'appended value']
d = {'int_value':3, 'bool_value':False, 'str_value':'hello'}
d.update({'str_value':'new_value', 'new_key':'new_value'})
d
{'bool_value': False,
'int_value': 3,
'new_key': 'new_value',
'str_value': 'new_value'}
d.append('hello')
------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-42922a99ec56> in <module>()
<hr />-> 1 d.append('hello')
AttributeError: 'dict' object has no attribute 'append'
numpy
pandas
library(readr)
dat <- read_csv('my_file.csv')
import numpy
arr = numpy.loadtxt('my_file.csv', delimiter=',')
import numpy as np
arr = np.loadtxt('my_file.csv', delimiter=',')
import pandas as pd
df = pd.read_csv('my_file.csv')
df.head()
Python for R Users