import pandas as pd
numericalSeries = pd.Series([10,21,32,43])
numericalSeries
CharacterSeries = pd.Series(['a','b','c'])
CharacterSeries
import numpy as np
numpySeries = pd.Series(np.random.randn(10))
numpySeries
numpySeriesWithIndex = pd.Series(np.random.randn(10),index=['a','b','c','d','e','f','g','h','i','j'])
numpySeriesWithIndex
dictionary = {'a' : 1,'b' : 2,'c' : 3,'d' : 4,'e' : 5,'f' : 6,'g' : 7,'h' : 8,'i' : 9,'j' : 10}
numpySeriesWithIndexFromDict = pd.Series(dictionary)
numpySeriesWithIndexFromDict
numpySeriesWithIndexFromDict[0] # first element of the Series
numpySeriesWithIndexFromDict[-1] # last element of the Series
numpySeriesWithIndexFromDict[5:-2] # from sixth element (index=5) to penultimate element (index=-2)
numpySeriesWithIndexFromDict['b']
numpySeriesWithIndexFromDict + 2
numpySeriesWithIndexFromDict / 2
numpySeriesWithIndexFromDict ** 2
twoColDataframe = pd.DataFrame({'var1' : [1,2,3,4,5], 'var2' : np.random.rand(5)})
twoColDataframe
dataframeFromDictionary = pd.DataFrame([dictionary]) # if passed as imput to a dataframe, each dictionary entry will became a column
dataframeFromDictionary
filename = 'data2CSV.csv'
twoColDataframe.to_csv(filename)
newDataframeFromFile = pd.read_csv(filename)
newDataframeFromFile
twoColDataframe.to_csv(filename,sep="\t",index=False);
newDataframeFromFile=pd.read_csv(filename,sep="\t")
newDataframeFromFile