Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Data Visualization Manual

The document is a manual for data visualization using Python's pandas and NumPy libraries, covering practical exercises on creating and manipulating one-dimensional and two-dimensional data structures. It includes examples of series operations, data frame creation, and basic data analysis techniques. Additionally, it outlines steps for connecting to data resources and performing calculations in Tableau.

Uploaded by

shaikhaaqif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Data Visualization Manual

The document is a manual for data visualization using Python's pandas and NumPy libraries, covering practical exercises on creating and manipulating one-dimensional and two-dimensional data structures. It includes examples of series operations, data frame creation, and basic data analysis techniques. Additionally, it outlines steps for connecting to data resources and performing calculations in Tableau.

Uploaded by

shaikhaaqif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

D.B.J.

College

ChiplunDataVisualization

Manual

PracticalNo.1

Name:Createone-dimensionaldatausingseriesandperformvariousoperationsonit. Input:

importnumpyasnp

importpandasaspd

#CreatingaSeriesofNdarrayDatawithLabels

Series1=pd.Series(np.random.randn(4),index=['a','b','c','d'])

print(Series1)

print(Series1.index)

Output:

a0.061086

b0.292177

c0.019949

d-0.223200

dtype:float64

Index(['a','b','c','d'],dtype='object')

#CreatingaSeriesofNdarrayDataWithoutLabels

Series2 = pd.Series(np.random.randn(4))

print(Series2)

print(Series2.index)

#SlicingDatafromaSeries

print (" \n Series slicing ")

print (Series1[:3])

print("\nIndexaccessing")

print(Series1[[3,1,0]])
print("\nSingleindex")

x = Series1[0]

print (x)

Output:

Seriesslicing

a-0.158575

b-0.685036

c-1.611250

dtype:float64

Index accessing

d 1.273993
b -0.685036
-0.158575

dtype:float64

Single index

-0.1585751050260909

#SampleOperationsinaSeries

print("\nSeriesSampleoperations")

print("\nSeriesvaluesgreaterthanthemean:%.4f"%Series1.mean()) print

(Series1 [Series1> Series1.mean()])

print("\nSeriesvaluesgreaterthantheMeadian:%.4f"%Series1.median()) print

(Series1 [Series1> Series1.median()])

print("\nExponentialvalue")

Series1Exp = np.exp(Series1)

print (Series1Exp)

Output:

SeriesSampleoperations

Seriesvaluesgreaterthanthemean:-0.2952
a-0.158575

d1.273993

dtype:float64

SeriesvaluesgreaterthantheMeadian:-0.4218 a-

0.158575

d1.273993

dtype:float64

Exponential value

a0.853359

b0.504072

c0.199638

d3.575101

dtype:float64

#CreatingaSeriesfromaDictionary print
("\nSeries of non declared index")

SeriesDict1 = pd.Series(dict)

print(SeriesDict1)

print("\nSeriesofdeclaredindex")

SeriesDict2=pd.Series(dict,index=['y','m','d','s'])

print(SeriesDict2)

Output:

Seriesofnondeclaredindex

m 2

y 2018

dSunday

dtype:object

Seriesofdeclaredindex y

2018
m 2

dSunday

s NaN

dtype:object

#AlteringaSeriesandUsingtheGet()Method

print("\nUsethegetandsetmethodstoaccess""aseriesvaluesbyindexlabel\n")

SeriesDict2 = pd.Series(dict, index=['y', 'm', 'd','s'])

print(SeriesDict2['y'])

SeriesDict2['y']=1999

print (SeriesDict2)

print(SeriesDict2.get('y'))

Output:

Usethegetandsetmethodstoaccessaseriesvaluesbyindexlabel 2018

y 1999

m 2

dSunday

s NaN

dtype: object

1999

#Creating a Series Using a Scalar Value

print("\ncreateseriesformscalarvalue") Scl =

pd.Series(8., index=['a', 'b', 'c', 'd']) print

(Scl)

Output:
createseriesformscalarvalue a

8.0
b8.0

c8.0

d8.0

dtype:float64

#VectorizingOperationsonaSeries

SerX=pd.Series([1,2,3,4],index=['a','b','c','d']) print

("Addition");

print(SerX+ SerX)

print("Additionwithnon-matchedlabel");

print (SerX[1:] + SerX[:-1])

print("Multiplication");

print (SerX * SerX)print

("Exponential"); print

(np.exp(SerX)) Output:

Addition

a 2

b 4

c 6

d 8

dtype:int64

Additionwithnon-matchedlabel

a NaN

b 4.0

c 6.0

d NaN

dtype:float64

Multiplication
a 1

b 4

c 9

d 16

dtype:int64

Exponential

a 2.718282

b 7.389056

c20.085537

d54.598150

dtype:float64

#UsingaSeriesNameAttribute

std=pd.Series([77,89,65,90],name='StudentsMarks') print

(std.name)

std=std.rename("Marks")

Output:

StudentsMarks

Marks
PracticalNO.2

Name:CreateTwo-dimensionaldatawiththehelpofdataframesandperformdifferentoperationson it.

Input:

importpandasaspd

data=[['Ossama',25],['Ali',43],['Ziad',32]]

DF1=pd.DataFrame(data,columns=['Name','Age'])

print (DF1)

data=[['Ossama',25],['Ali',43],['Ziad',32]]

DF1=pd.DataFrame(data,columns=['Name','Age'],dtype=float) print

(DF1)

output:

NameAge

0 Ossama 25.0

1 Ali 43.0

2 Ziad 32.0

data=[{'Test1':10,'Test2':20},{'Test1':30,'Test2':20,'Project':20}]

df1 = pd.DataFrame(data, index=['First', 'Second'],columns=['Test2', 'Project' , 'Test1'])

df2=pd.DataFrame(data,index=['First','Second'],columns=['Project','Test_1','Test2'])

print (df1)

print("\n")

print (df2)
Output:

Test2ProjectTest1

First 20 NaN 10

Second 20 20.0 30

Project Test_1 Test2

First NaN NaN NaN

Second20.0 NaN NaN

data={'Test1':pd.Series([70,55,89],index=['Ahmed','Omar','Ali']),

'Test2':pd.Series([56,82,77,65],index=['Ahmed','Omar','Ali','Salwa'])} df1 =

pd.DataFrame(data)

print(df1)

Output:

Test1 Te
st
2
Ahmed70.0 56

Ali 89.0 77

Omar55.0 82
Salwa NaN 65

#columnaddand del

df1['Project']=pd.Series([90,83,67,87],index=['Ali','Omar','Salwa','Ahmed'])

print ("\n")

df1['Average']=round((df1['Test1']+df1['Test2']+df1['Project'])/3,2) print

(df1)

df2= df1
df2.pop('Project')
print(df2)

Output:

Test1Test2ProjectAverage

Ahmed70.0 56 8771.00

Ali 89.0 77 9085.33

Omar55.0 82 8373.33

SalwaNaN 65 67 NaN

Test1Test2Average

Ahmed70.0 5671.00

Ali 89.0 7785.33

Omar55.0 8273.33

SalwaNaN 65 NaN

#slicethe row

print("\nslicerows")

print (df1[2:4])

Output:

Test1Test2Average

Omar55.0 8273.33

SalwaNaN 65 NaN

#columnadd

data={'Test1':pd.Series([70,55,89],index=['Ahmed','Omar','Ali']),

'Test2':pd.Series([56,82,77,65],index=['Ahmed','Omar','Ali','Salwa'])}

df2=pd.DataFrame([[80,70,90,80]],columns=['Test1','Test2','Project','Average'],index=['Khalid'])

data.append(df2)
Practicalno.3

Name:WriteacodetoreaddatafromthedifferentfileformatslikeJSON,HTML,XML,andCSVfilesand check for


missing data and outlier values and handle them
PracticalNo.4

Performreshapingofthehierarchicaldataandpivotingdataframedata

importpandasaspd

importnumpyasnp

data = pd.DataFrame(np.arange(6).reshape((2, 3)),

index=pd.Index(['Ohio', 'Colorado'], name='state'),

columns=pd.Index(['one','two','three'],name='number'))

print(data)

Output:

numberonetwothree

state

Ohio 01 2

Colorado34 5

result=data.stack()

print(result)output:

state number

Ohio one 0

two 1

three 2

Coloradoone 3

two 4

three 5

dtype: int32

result1=data.unstack()
print(result1)
Output:

numberstate

one Ohio 0
Colorado 3

two Ohio 1
Colorado 4

threeOhio 2

Colorado5

dtype: int32
Practicalno.5

Name: Connecting and extracting with various data resources in tableau.

Step 1: Open the tableau:

Step2:Connectthetext file.

Step3: Select the .csv file and open it.


Step5: Connect the Microsoft Excel file.
Step6: Select the excel file and open it.

Step7:Drag and drop the tables.

.
Step8:Open the worksheet.
PracticalNo.6

Name:PerformingcalculationsandcreatingparametersinTableau.
Practicalno.7:

Name:DesigningTableauDashboardsfordifferentdisplaysanddevices.

Step 1: Click the dashboard sheet.

Step2:Clicktonewdashboardmenu.
PracticalNo.8

Name:CreateaTrendmodelusingdata,Analyze-itanduseitfor forecasting.

Clicktoanalysispanetoselectthetrandlineclickandselecttotheshowtrandline.
Showthetrendline.

Clicktoanalysispanethenselecttotheforecastclickandselectshowforecast.
Showthe forecast.
Practicalno.9

Name:CreatingGeospatialfeaturemapsinTableauusingGeospatialData. Step 1:

click the map pane and select the background image.

Ste2:selectthebackgroundimageandselectdarkoption.

Step3:selectthebackgroundlayer.

You might also like