0 ratings 0% found this document useful (0 votes) 16 views 12 pages Fbdata Assignment
The document appears to be a Jupyter notebook containing Python code for analyzing a Facebook user dataset using libraries like NumPy, Pandas, and Seaborn. It includes data manipulation, visualization, and statistical analysis to explore user demographics, friendships, and trends. Key analyses involve gender distribution, friend counts, and friendships initiated by gender, with visualizations such as count plots and bar plots to represent the findings.
AI-enhanced title and description
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
218128, 12:58 AM
soar numpy as np # nunpy for nunericat sperations
frport pandas as pd 8 pandas for data manipulation
‘rport [Link]
‘nport seaborn as sns # 38 graph visuaiszation
6 = p.rend_cxv("/content/ facebook user. data
userid age dob_cay dob year 4
4 82001
3 20.168
4 saat
Next tps: (Genwi
“4
“4
smead{) # view cop 5 cara
2 1999 1 forste
2 1980 12 forsale
4 1909 12 male
ahat) (Newineracve sheet)
eFsinfo() # get the information of dataset
bataérane>
Rangeradex: 99803 entries, @ to 99002
Date coluene (total 15 cols).
sae
°
2 Gooey
3 dob-yeae
®
ender
30 kes received
Teer
3 mooi
received $9903 non-null
orn
ron-nuk
ror-nut
ron-nitk
torn
ton-nul
ron-nuth
types? FioatGa(a), Inese(aa), edseer)
renory usage: 11.36 m8
Asm ().aum) # check £f there null value
|ntps:ifolab research google.comvdrve1bhROKAVTSzxymyHptzge MAz-2Mq4BiscrolTo=GOUKSICBLS_w&printMoce=true
pt 1 24 graph visualization
60
130
m0
220
ay2ipynb- Colas
(2) = faebook_usor-data (2).c80") # Toad the dataset
°
°
°
°
gender tenure friend count friendships initiated 1lkes kes received mobi
°
°
°
ane218128, 12:58 AM [Link]- Colao
id °
friendshipsiniiated 0
es receved 0
mob
2 = Siapleinputer(serateny~"nost_frequent”)
et gender = a: fi¢_transform(df[ Gender" }-[Link](-3,3))-flatten()
Fs Asnuni() sunt)
dob year 0
gender °
kes °
mobile tikes 0
wow thes 0
type: ins
» » sinpleinputer(strateny~"nadtan")
ef cenure » b.t35_transtore(al "tenure" values. reshape|
20)).A
0
F-Asnutl().sum() feheck whe auld values again to confirm it's already saputed
!ntps:ifolab research google.comvdrve1bfhROKAVTSzxymyHptzge MAz-2Mq4B#scroTo=GOUKSICBLS_w&printMoce=true ane218128, 12:58 AM
columse["userid’, “age, “oe
sfopd.rend_cav(”/contenty/ nw. facebook_user data. civ")
etneadO)
‘unnanes
2onaees
1203168
‘739106
“
161999
a)
4 1990
Nort stepe: (Generate code with) (New hteracve sheet)
ef. drop ants
, colunns="Uonaned: @, Inplace-true)
eFsnead()
userid age dob day dob_year dob_month gender
0 20082 14 a8 1000 male
2 rommee 4161000 male
re ) 12 malo
ex ateps: (Generate code witha)
ef Asmat ()-sum()
|ntpsifolab research google.comvdrve1bhROKAVTSzxymyHptzge MAz-2Mq4BiscrolTo=GOUKSICBLS_w&printMoc
(Cow inratv set )
[Link]- Colao
12 feral
2580
130
220
ie 190
le 930
e820
‘friend_court friendships initiated
°
o
°
°
asker
°
0 0
o 6
o 0
ikes_recesved mobs
°
°
ane218128, 12:58 AM [Link]- Colao
friendships_iniated 0
ndex((‘useria, ‘age, “dob _day', ‘dob year’, ‘dob-nonth', ‘gender’, tenure’,
“tend count’, "friendships initiated, "likes", ‘itkes receive,
om Lies received"), oa
exper onjeet')
etme = de{{'usertd®, ‘age’, “dob aay", "sou year', “dab_nanth’, “venure’,
m_13kes_received']] oa
[Link]() sew correlation
userid age dob ay dob year [Link] tenure friend count friendships initiated ik
‘000000 -2.007265 -0.000829 007265 oem -ooneK49 0.001214 2.001801 0.0028
aye 2007265 ‘.000009 .025095 1.900000 paaste? o4sae%e — -a.0274a7 -o.0se089 2.0120
dob dey 0.000830 0.085035 1.000000 -n.035085 120443 oueTEse —_.a2t981 0.022080 0.018%
dob_year 0.007265 1.000000 0.035035 1.000000 .n02st67 0462098 aczr40r 0.058059 0.0130
‘dob_month 01002024 0026167 0.129449 0.025167 1.900000 0.920445 0.010804 020075 ates
ftiend_count — -0.001314 0.021407 0021961 c2r407 o.0T98D4 0.186257 1.000000 0.925850 0.2000
‘endehipsniisted 2001591 2088059 acz2909 acsa0s9 020075 0.155507 0.825850, ‘000000 0.2855
hes 0.002875 2.012008 0.015680 o.912009 OO14NA7 onsT182 0298017 0.285582 1.9000
mobile likes 0004862 0.028715 .0v4841 0.026715 .010400 onae0s 0235856 0.220008 o.7i6:
wom_ikes 0001828 0.015585 009959 -norssas oo1zIa8 onvoTs? 0.220809 o2Moze 06x
[Link](#igatze-(25,8)) 4 plot heatnap to see correlation between features
fnasheataap(df_pev.corr(), annot-Trve)
ana
|ntpsifolab research google.comvdrve1bfhROKAVTSzxymyHptzge MAz-2Mq4B#scrolTo=GOUKSICBLS_w&printMoc218/26, 12:58 AM [Link]- Colao
‘fron skiearn inport preprocessing
2» = [Link]() # encoder
¢{"gander"Jo a.fis_transtorn(4f{ "gender" [Link](-t,1)) -flatten() encode the cagetoricat value to number
fsnead()
Jusr/local/tb/pythons.22/4tst-packages/sklearn/preprocessing/_abel.py:ii#: DataConverstonkarning: A colunn-vector y ¥as pass
YY = colunnse tuty, warnsTrue)
userid age dob_day dob year deb #
kes 1skes received mobs
toe ee oe : :
me ; :
PES ; ;
eS ; ;
sen: et ne) Cen)
[Link]()
ntps:folab research [Link] MAz-2Mq4B#scroTo=GOUKSFCBLS_w&printMode=tte sre218/26, 12:58 AM [Link] - Colao
usentd age [Link] dob_year [Link] gander tenure. frtend_count _frtendships_initist:
‘rend “.n00000 -0.007265 0.000899 007265 0.002924 9.001670 -o.00aK49 0.001814 0.0018:
0.007265 ‘000002 0.035095 1.900000 oaas6r -Do7ger1 o4sa6% -002r40r 2.0500,
0.000899 0.035025 1.000000 0.095035 0.129443 0.040879 onHT85 ——_o2T961 0.0228
(0.007265 1.000000 -2.035035 1.900000 0.025167 o.079871 0.482595 027407 2.0580:
‘9.02524 9.025167 0.129442 -0.025167 000000 0.035755. 0.020445 o.oT980 0.0200
0001870 2.07887: -2.0%8573 0.078871 0035755 «000000 -a089255 -a.ca7409 2.0282,
0.003449 0.462805 0.041859 0.462688 D.n29445. 0.090255 +000000 0.168257 0.39951
‘Wiend_count 9.001914 2027407 021981 ac2r4a7 oot9eD4 -oon7499 o.18e257 1.900000 nase,
friendships nated 0001591 2058059 0022000 088059 o.020075 9.028285 0.183507 0.825850, 1.00001
kes 2.002875 2.012008 0.018880 o.9t2009 OO14447 -O.As0a89 ons7189 —ozaa017 oss:
[Link] 0.001528 0.022570 0.001367 0.022570 006495 0.054857 o.027745 0.236483 ors
mobile likes 2.004858 2.025735 .ov4s41 0.026715 o.010400 -o.124181 9028053 a.za5858 0.296,
‘mobilekes_recelved 0.001753 0.024248 0.000487 0.024248 9.008435 2.02071 0287 aza2701 0798,
wimikes 0.001828 OOISSES 008359 -aotssaS o1zI36 04107763 oorors? 0.220809, a2,
worm ikesreceved 0001074 0018224 002460 cot8224 0.006003 0.062900 [Link] —o.220727 ose
ple. subplots(figsize-(25,8))
[Link](@[Link](), annot=T-ue)
caves: >
43.1) what 1 composition of male and female users?
{f(-gender*].vsiue,counts() 4 view the each total value fn toth gender
ntps:folab research [Link] IMAz-2Mq4B#scroTo=GOUKSICBLS_w&printMode=ttue, ene218128, 12:58 AM [Link]- Colao
sender
+ sama
© 40258
ctype: ise
[Link](asaf{ "gender", palettes'virisis’, order=[2,8))
[Link]( gender’) # x aber
pPUtiylabel(‘tetal population’) # y Labed
PIE. tLtLe(‘Conposition oF Made and Fenale Users") # graph title
plecxtcks([@,a], ["male", "fenale”]) # x tieks to mapped @ and 2 a5 male and fenale
[Link]()
‘tno Lpython-Lnput- 2047852027 py:8: Futurelarning
Passing “palette” without assigning “Me” Ls deprecated and will be removed in v®.14.8. Assign the “x° variable to “hue” and s
[Link](acdff ‘gender"], palevte~'vinidis', order-[1,0])
Composition of Male and Female Users
60000.
3
8
total population
g
8
20000:
‘male female
ender
73.2) Wnten category of gender has nore fotends?
F{"Fetend_count®J.value_counts()
ntps:folab research [Link] MAz-2Mq4B#scroTo=GOUKSFCBLS_w&printMode=tte me218128, 12:58 AM [Link]- Colao
ntpssioolab es
° 1982
4 1816
3 980
zou 1
os 1
2606 1
2004 1
2862 ows = columns
ctype: ins
eF(aFL gender*
1)("frtend court’ .sun() deheck the total friends for male users
[Link](9e53059)
eF{4tL gender” = @){ "friend count'|.sun() # check the total fofends of female users
np. tnse(o740258)
[Link] (wnat T "gender", y-df{ "frend count’, pale
pltcxdabel('gender') # x Iabet
pltcylabel ‘average friend count") # y label changed to reflect ‘barplot’ default behavior
pie-titie(‘unieh category of gender has nore ¢riends?") # graph ticle
plevaticks([@,3], "male", "ferale"]) # x tices to mapped @ and 2 ne nale and female
"viridis", ordorst1,0], hued gender" })
[Link]()
Which category of gender has more friends?
250] gender
mo
—_.
3 150
&
2
50
male female
gender
49.3) bien category of gender initiates nove friendships
iale_¢riendships initiated = of-loc(d¢{ gender] == 1, "flendships_initistea’].sun() # get total friendships initiated of ma
Print(eTotal tiendsnipe instiatee by mple users: (nale_friendships_snstiated)")
enaie_frtendships initiated = of loc[df[ gender’ == 8, ‘Itendships_sntttated’].sun() # get total (rtendships_sniciates of
prine(#"Total friendships initiated by ferale users: (fenale_fetencships_initiated}")
rch google. comidrive 1 bROKIVTSzxymyHptzge IMAz-2Mq4BAscroTo=GOUKEFCBLS_w&printMode=tue
ane218128, 12:58 AM [Link]- Colao
Total #rLendships initiates by male users: 6953223
Total friendships initiates by fenale users! #561894
‘riendship_data = pd-Datatrane((
‘Gender’: [hale’, “Female” Jy
‘rlendships Initiated’: (nae friendships initiated, fenale_friendships_initiated]
2) # eneate sub astafrone for plot
pit. tigura(tigssze-(8, 6))
[Link] (x
prestitiet™
pie-xlabel( Gender)
pievylabel( Total Friendenips initiates!)
[Link]()
‘viridis’, data-friendship dats, hue-"Gonder’, Tegend-Fotse)
166, ‘Total Friendships Initiated by Gender
Total Friendship tiated
2
ccenger
3.4) The distribution of tenure across different categories of gender
[Link] xaét[ gender"), yadf["tenure'], palettes"vinieis")
pltsndabel( gender) # x label
plt-ylabel(‘tenure') # y label
PLL. tatLe("Tae disteSbution of tenure across aifferant categories of gender") # graph title
pit-xticks((@,a], ("aale”, "fenale”]) # x ticks Uo wapped @ and 2 25 male and fenale
[Link]()
one
ntps:folab research [Link] IMAz-2Mq4B#scroTo=GOUKSICBLS_w&printMode=ttue,218128, 12:58 AM [Link]- Colao
‘tnp/ipython-input- 4884485275. py:2: Futurehurning:
Passing “palette’ without assigning “Me” {4 deprecated and will be removed in v®.14.8. Attign the “x° variable to “hut and s
[Link](avaf{ gender"), yodf{‘tenure'], palettes"virdess")
The distribution of tenure across different categories of gender
600
500
400
§
gm
200
°
male female
gender
14.2) How many users have no fetends
{eF("Fetend_count®J.value_counts()[@) # view the total user with no friends
np-tntse(a962)
ple. figure(eigsszea(8,3))
Po_Sriends_count Af friend_court].vatee_counts()(0]
[Link] (x= [ne_frsends count], palettes viriais’)
pltiylabel ‘users with no Friends")
[Link] number of Users")
Ple-titie("how mary users have no frdends")
pitsshow()
‘apr ipython-input-1261082274, 9:3: Futuredorning
Passing “polette’ without assigning “hue” ts deprecated and will be removed in v®.28.0. Assign the “y" variable to “hue” and =
[Link](x-[no_frdends_count], palettes‘virsets")
How many users have no friends
Users with ne Friends
mo 1000 =—«a250~—=«s0 «ATO
Number of users
14.2) How many users did nat 16ke any posts
eF{"13kes"] value counts(){@] # view the total user sith 10 kes
np. tese(22308)
ntps:folab research google. comdrve HROKVTSzxymyHptzge MAz-2Mq4BAscroTo=GOUKSFCBLS_w&printMode=ttue, sore218128, 12:58 AM [Link]- Colas
pit. igure(Figsize-(10,3))
[Link] (x=(@f" Likes ].value_counts()[@)], paletter'viridis')
plt-xlabel('nunber of popslation®)
[Link](‘nunber of people did rot like any post’, rotatdone"vertical’)
PIE. titLe(” How many users dé not Like any posts")
‘/rap/[Link]+ Futuesaening!
Passing “polette’ without assigning “hue” 1s deprecated and will be renoved in vB.14.8. Assign the 'y' variable to “hue and s
srs. barplot (nel f"1Skes'].value_counts()[0]], palettes'viriais")
Text(@.5, 118, How nany users o3d not like any posts")
How many users did not like any posts
number of people did nat Hee any post
10000 15000
numberof population
4.3) How many users dtd not recetve ary kes
2¢("13kes_recesved" J-value_counts()(@] # view the total user uth no Tikes recetved
np. ttse(24ara)
pit. sure(tigssze-(28,9))
[Link] (xo[af Tikes receives"
ple-xiabel(" nunber of population’)
pltsylabel(nunber of people who cid not receive any tie")
PIELEIRLe("How mary users did not receive any Tikes")
value_counts(){O]], palettes'viridis")
‘/tap/ython-Snput-201075362. 9:22 Futuresorning
Passing “palette” without assigning “hue is deprecated and will be renoved in vB.14.0. Assign the 'y' variable to “hue and s
srs. barplot(xa[ ef "10kes_recetved").vaiue_counts()(0]]}, palettes'virsats')
Tegtl@.5, 118, "How many users dia not receive any Likes")
How many users did not receive any likes
°
10000 15000
‘numberof population
umber of people wha did nat receive any
2 = at[aontte iikes received") > @
walue_counts)
fit displays total nunber of users 2iked received by nobile is 62000
ntps:folab research [Link] MAz-2Mq4B#scroTo=GOUKSFCBLS_w&printMode=tte se218128, 12:58.
ntpssioolab es
M [Link]- Colao
robile Likes received
we 9000
A 0002
oF toc{éFt"gender'] =» 1, ‘nobite_Tikes received’
robile_1tkes_recesved
°
7024
were
PEED
98748 rs #1 columns
type: ies
45.1) what is the total number of posts Liked by users (based on gender) through webile devices
[Link] (anf I" gender’, yodf['nobie_Likes received’) > @, palette~
plesxlabel('gender')
plesylabel('nobile_1ikes_recetvee')
plestitle("shat is the total umber of posts 2iked by users (based on genéer) through nobile devices")
plesxticks((@,a], (nale", "enale"])
plt-show)
viridis", order-[2,01)
‘/rap/oython-Soput-1635243184, "3: Futunesaening!
Passing “palette” without assigning “nue” 1s deprecated and will be removed 4n v®.34.8. Assign the “x” varSable to “hue” and =
[Link](wsati"gender'], yedf{‘nobile_Likes_received’] > @, palettos"vinédss", ondere[1,81)
What is the total number of posts liked by users (based on gender) through mobile devices
oe
mobile tikes received
male female
gender
rch google. comdrivebHROKIVTSzxymyHptzgc IMAz-2Mq4B#scroTo=GOUKSFCBLS_w&printMode=tue. rane