0% found this document useful (0 votes)
8 views13 pages

Practical 4

The document provides a detailed overview of a Facebook dataset loaded into a Pandas DataFrame, including its structure, data types, and initial data exploration. It contains 500 entries with 19 columns, covering various metrics related to Facebook posts such as likes, shares, and engagement. The document also demonstrates data manipulation techniques including filtering, sorting, and selecting specific subsets of data.

Uploaded by

rajdebadwar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

Practical 4

The document provides a detailed overview of a Facebook dataset loaded into a Pandas DataFrame, including its structure, data types, and initial data exploration. It contains 500 entries with 19 columns, covering various metrics related to Facebook posts such as likes, shares, and engagement. The document also demonstrates data manipulation techniques including filtering, sorting, and selecting specific subsets of data.

Uploaded by

rajdebadwar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

In [1]: import pandas as pd

import numpy as np

In [2]: df = pd.read_csv("dataset_Facebook.csv", sep=';')

In [3]: [Link]()

Out[3]:

Lifetime
Page Lifetime Life
Post Post Post Post
total Type Category Paid Post Total Eng
Month Weekday Hour Total
likes Impressions U
Reach

0 139441 Photo 2 12 4 3 0.0 2752 5091

1 139441 Status 2 12 3 10 0.0 10460 19057

2 139441 Photo 3 12 3 3 0.0 2413 4373

3 139441 Photo 2 12 2 10 1.0 50128 87991

4 139441 Photo 2 12 2 3 0.0 7244 13594

 

In [4]: [Link]()
<class '[Link]'>
RangeIndex: 500 entries, 0 to 499
Data columns (total 19 columns):
# Column Non-Nul
l Count Dtype
--- ------ -------
------- -----
0 Page total likes 500 non
-null int64
1 Type 500 non
-null object
2 Category 500 non
-null int64
3 Post Month 500 non
-null int64
4 Post Weekday 500 non
-null int64
5 Post Hour 500 non
-null int64
6 Paid 499 non
-null float64
7 Lifetime Post Total Reach 500 non
-null int64
8 Lifetime Post Total Impressions 500 non
-null int64
9 Lifetime Engaged Users 500 non
-null int64
10 Lifetime Post Consumers 500 non
-null int64
11 Lifetime Post Consumptions 500 non
-null int64
12 Lifetime Post Impressions by people who have liked your Page 500 non
-null int64
13 Lifetime Post reach by people who like your Page 500 non
-null int64
14 Lifetime People who have liked your Page and engaged with your post 500 non
-null int64
15 comment 500 non
-null int64
16 like 499 non
-null float64
17 share 496 non
-null float64
18 Total Interactions 500 non
-null int64
dtypes: float64(3), int64(15), object(1)
memory usage: 74.3+ KB

In [5]: subset_loc = [Link][0:10, ['like', 'share']]


print(subset_loc)
like share
0 79.0 17.0
1 130.0 29.0
2 66.0 14.0
3 1572.0 147.0
4 325.0 49.0
5 152.0 33.0
6 249.0 27.0
7 325.0 14.0
8 161.0 31.0
9 113.0 26.0
10 233.0 19.0

In [6]: subset_iloc = [Link][0:10, 0:5]


print(subset_iloc)

Page total likes Type Category Post Month Post Weekday


0 139441 Photo 2 12 4
1 139441 Status 2 12 3
2 139441 Photo 3 12 3
3 139441 Photo 2 12 2
4 139441 Photo 2 12 2
5 139441 Status 2 12 1
6 139441 Photo 3 12 1
7 139441 Photo 3 12 7
8 139441 Status 2 12 7
9 139441 Photo 3 12 6

In [7]: subset_cols = df[['like', 'share']]


print(subset_cols)

like share
0 79.0 17.0
1 130.0 29.0
2 66.0 14.0
3 1572.0 147.0
4 325.0 49.0
.. ... ...
495 53.0 26.0
496 53.0 22.0
497 93.0 18.0
498 91.0 38.0
499 91.0 28.0

[500 rows x 2 columns]

In [8]: high_likes = df[df['like'] > 100]


print(high_likes)
Page total likes Type Category Post Month Post Weekday Post Hour \
1 139441 Status 2 12 3 10
3 139441 Photo 2 12 2 10
4 139441 Photo 2 12 2 3
5 139441 Status 2 12 1 9
6 139441 Photo 3 12 1 3
.. ... ... ... ... ... ...
488 85979 Photo 3 1 7 10
491 85979 Photo 3 1 6 3
492 85979 Link 1 1 5 11
493 85093 Photo 3 1 1 2
494 85093 Photo 3 1 7 10

Paid Lifetime Post Total Reach Lifetime Post Total Impressions \


1 0.0 10460 19057
3 1.0 50128 87991
4 0.0 7244 13594
5 0.0 10472 20849
6 1.0 11692 19479
.. ... ... ...
488 0.0 9700 17442
491 1.0 6184 10228
492 0.0 45920 5808
493 0.0 8412 13960
494 0.0 5400 9218

Lifetime Engaged Users Lifetime Post Consumers \


1 1457 1361
3 2211 790
4 671 410
5 1191 1073
6 481 265
.. ... ...
488 1407 1271
491 956 901
492 753 655
493 1179 1111
494 810 756

Lifetime Post Consumptions \


1 1674
3 1119
4 580
5 1389
6 364
.. ...
488 2007
491 1140
492 763
493 1632
494 1003

Lifetime Post Impressions by people who have liked your Page \


1 11710
3 61027
4 6228
5 16034
6 15432
.. ...
488 8872
491 6085
492 15766
493 8632
494 5654

Lifetime Post reach by people who like your Page \


1 6112
3 32048
4 3200
5 7852
6 9328
.. ...
488 4876
491 3502
492 10720
493 5348
494 3230

Lifetime People who have liked your Page and engaged with your post \
1 1108
3 1386
4 396
5 1016
6 379
.. ...
488 660
491 437
492 220
493 699
494 422

comment like share Total Interactions


1 5 130.0 29.0 164
3 58 1572.0 147.0 1777
4 19 325.0 49.0 393
5 1 152.0 33.0 186
6 3 249.0 27.0 279
.. ... ... ... ...
488 21 277.0 80.0 378
491 1 105.0 46.0 152
492 0 128.0 9.0 137
493 17 185.0 55.0 257
494 10 125.0 41.0 176

[252 rows x 19 columns]

In [9]: sorted_df = df.sort_values(by='like')


print(sorted_df.head())
Page total likes Type Category Post Month Post Weekday Post Hour \
21 138414 Photo 1 12 7 10
441 98195 Photo 1 3 5 4
76 137893 Photo 1 11 3 2
417 104070 Photo 1 3 3 10
100 137020 Photo 1 10 4 9

Paid Lifetime Post Total Reach Lifetime Post Total Impressions \


21 0.0 1384 2467
441 1.0 1845 2670
76 0.0 1228 2392
417 0.0 1874 2474
100 1.0 1357 2453

Lifetime Engaged Users Lifetime Post Consumers \


21 15 15
441 9 9
76 17 17
417 25 25
100 37 37

Lifetime Post Consumptions \


21 20
441 9
76 19
417 31
100 55

Lifetime Post Impressions by people who have liked your Page \


21 2196
441 1614
76 2392
417 1483
100 2154

Lifetime Post reach by people who like your Page \


21 1172
441 1008
76 1228
417 1062
100 1120

Lifetime People who have liked your Page and engaged with your post \
21 15
441 9
76 17
417 15
100 32

comment like share Total Interactions


21 0 0.0 0.0 0
441 0 0.0 0.0 0
76 0 0.0 0.0 0
417 0 0.0 0.0 0
100 0 0.0 0.0 0

In [10]: sorted_desc = df.sort_values(by='like', ascending=False)


print(sorted_desc.head())
Page total likes Type Category Post Month Post Weekday Post Hour \
244 130791 Photo 2 7 3 5
379 111620 Photo 3 4 1 14
349 117764 Photo 3 5 5 13
168 135428 Photo 1 9 3 10
3 139441 Photo 2 12 2 10

Paid Lifetime Post Total Reach Lifetime Post Total Impressions \


244 1.0 180480 319133
379 1.0 105632 147918
349 0.0 81856 124753
168 0.0 41984 68290
3 1.0 50128 87991

Lifetime Engaged Users Lifetime Post Consumers \


244 8072 4010
379 3984 2254
349 3000 1637
168 3370 2420
3 2211 790

Lifetime Post Consumptions \


244 6242
379 3391
349 2718
168 4074
3 1119

Lifetime Post Impressions by people who have liked your Page \


244 108752
379 48575
349 52477
168 34802
3 61027

Lifetime Post reach by people who like your Page \


244 51456
379 27328
349 27392
168 20928
3 32048

Lifetime People who have liked your Page and engaged with your post \
244 3316
379 1936
349 1756
168 2126
3 1386

comment like share Total Interactions


244 372 5172.0 790.0 6334
379 51 1998.0 128.0 2177
349 45 1639.0 122.0 1806
168 144 1622.0 208.0 1974
3 58 1572.0 147.0 1777

In [11]: transposed_df = [Link]()


print(transposed_df)
0 1 2 \
Page total likes 139441 139441 139441
Type Photo Status Photo
Category 2 2 3
Post Month 12 12 12
Post Weekday 4 3 3
Post Hour 3 10 3
Paid 0.0 0.0 0.0
Lifetime Post Total Reach 2752 10460 2413
Lifetime Post Total Impressions 5091 19057 4373
Lifetime Engaged Users 178 1457 177
Lifetime Post Consumers 109 1361 113
Lifetime Post Consumptions 159 1674 154
Lifetime Post Impressions by people who have li... 3078 11710 2812
Lifetime Post reach by people who like your Page 1640 6112 1503
Lifetime People who have liked your Page and en... 119 1108 132
comment 4 5 0
like 79.0 130.0 66.0
share 17.0 29.0 14.0
Total Interactions 100 164 80

3 4 5 \
Page total likes 139441 139441 139441
Type Photo Photo Status
Category 2 2 2
Post Month 12 12 12
Post Weekday 2 2 1
Post Hour 10 3 9
Paid 1.0 0.0 0.0
Lifetime Post Total Reach 50128 7244 10472
Lifetime Post Total Impressions 87991 13594 20849
Lifetime Engaged Users 2211 671 1191
Lifetime Post Consumers 790 410 1073
Lifetime Post Consumptions 1119 580 1389
Lifetime Post Impressions by people who have li... 61027 6228 16034
Lifetime Post reach by people who like your Page 32048 3200 7852
Lifetime People who have liked your Page and en... 1386 396 1016
comment 58 19 1
like 1572.0 325.0 152.0
share 147.0 49.0 33.0
Total Interactions 1777 393 186

6 7 8 \
Page total likes 139441 139441 139441
Type Photo Photo Status
Category 3 3 2
Post Month 12 12 12
Post Weekday 1 7 7
Post Hour 3 9 3
Paid 1.0 1.0 0.0
Lifetime Post Total Reach 11692 13720 11844
Lifetime Post Total Impressions 19479 24137 22538
Lifetime Engaged Users 481 537 1530
Lifetime Post Consumers 265 232 1407
Lifetime Post Consumptions 364 305 1692
Lifetime Post Impressions by people who have li... 15432 19728 15220
Lifetime Post reach by people who like your Page 9328 11056 7912
Lifetime People who have liked your Page and en... 379 422 1250
comment 3 0 0
like 249.0 325.0 161.0
share 27.0 14.0 31.0
Total Interactions 279 339 192

9 ... 490 491 \


Page total likes 139441 ... 85979 85979
Type Photo ... Photo Photo
Category 3 ... 3 3
Post Month 12 ... 1 1
Post Weekday 6 ... 6 6
Post Hour 10 ... 11 3
Paid 0.0 ... 0.0 1.0
Lifetime Post Total Reach 4694 ... 5280 6184
Lifetime Post Total Impressions 8668 ... 8703 10228
Lifetime Engaged Users 280 ... 951 956
Lifetime Post Consumers 183 ... 911 901
Lifetime Post Consumptions 250 ... 1237 1140
Lifetime Post Impressions by people who have li... 4309 ... 5757 6085
Lifetime Post reach by people who like your Page 2324 ... 3300 3502
Lifetime People who have liked your Page and en... 199 ... 431 437
comment 3 ... 1 1
like 113.0 ... 79.0 105.0
share 26.0 ... 30.0 46.0
Total Interactions 142 ... 110 152

492 493 494 \


Page total likes 85979 85093 85093
Type Link Photo Photo
Category 1 3 3
Post Month 1 1 1
Post Weekday 5 1 7
Post Hour 11 2 10
Paid 0.0 0.0 0.0
Lifetime Post Total Reach 45920 8412 5400
Lifetime Post Total Impressions 5808 13960 9218
Lifetime Engaged Users 753 1179 810
Lifetime Post Consumers 655 1111 756
Lifetime Post Consumptions 763 1632 1003
Lifetime Post Impressions by people who have li... 15766 8632 5654
Lifetime Post reach by people who like your Page 10720 5348 3230
Lifetime People who have liked your Page and en... 220 699 422
comment 0 17 10
like 128.0 185.0 125.0
share 9.0 55.0 41.0
Total Interactions 137 257 176

495 496 497 \


Page total likes 85093 81370 81370
Type Photo Photo Photo
Category 3 2 1
Post Month 1 1 1
Post Weekday 7 5 5
Post Hour 2 8 2
Paid 0.0 0.0 0.0
Lifetime Post Total Reach 4684 3480 3778
Lifetime Post Total Impressions 7536 6229 7216
Lifetime Engaged Users 733 537 625
Lifetime Post Consumers 708 508 572
Lifetime Post Consumptions 985 687 795
Lifetime Post Impressions by people who have li... 4750 3961 4742
Lifetime Post reach by people who like your Page 2876 2104 2388
Lifetime People who have liked your Page and en... 392 301 363
comment 5 0 4
like 53.0 53.0 93.0
share 26.0 22.0 18.0
Total Interactions 84 75 115

498 499
Page total likes 81370 81370
Type Photo Photo
Category 3 2
Post Month 1 1
Post Weekday 4 4
Post Hour 11 4
Paid 0.0 NaN
Lifetime Post Total Reach 4156 4188
Lifetime Post Total Impressions 7564 7292
Lifetime Engaged Users 626 564
Lifetime Post Consumers 574 524
Lifetime Post Consumptions 832 743
Lifetime Post Impressions by people who have li... 4534 3861
Lifetime Post reach by people who like your Page 2452 2200
Lifetime People who have liked your Page and en... 370 316
comment 7 0
like 91.0 91.0
share 38.0 28.0
Total Interactions 136 119

[19 rows x 500 columns]

In [12]: df1 = df[['Page total likes', 'Type']]


df2 = df[['Page total likes', 'Category']]

In [13]: merged_df = [Link](df1, df2, on='Page total likes')


print(merged_df.head())

Page total likes Type Category


0 139441 Photo 2
1 139441 Photo 2
2 139441 Photo 3
3 139441 Photo 2
4 139441 Photo 2

In [14]: melted_df = [Link](df,


id_vars=['Type'],
value_vars=['like', 'share'],
var_name='Metrics',
value_name='Values')

print(melted_df.head())

Type Metrics Values


0 Photo like 79.0
1 Status like 130.0
2 Photo like 66.0
3 Photo like 1572.0
4 Photo like 325.0

In [15]: pivot_df = df.pivot_table(


index='Type',
values=['like', 'share'],
aggfunc='mean'
)

print(pivot_df)

like share
Type
Link 73.318182 12.909091
Photo 182.611765 27.158768
Status 176.711111 31.422222
Video 231.428571 52.142857

In [16]: print([Link]().sum())

Page total likes 0


Type 0
Category 0
Post Month 0
Post Weekday 0
Post Hour 0
Paid 1
Lifetime Post Total Reach 0
Lifetime Post Total Impressions 0
Lifetime Engaged Users 0
Lifetime Post Consumers 0
Lifetime Post Consumptions 0
Lifetime Post Impressions by people who have liked your Page 0
Lifetime Post reach by people who like your Page 0
Lifetime People who have liked your Page and engaged with your post 0
comment 0
like 1
share 4
Total Interactions 0
dtype: int64

In [17]: print([Link]())
Page total likes Category Post Month Post Weekday Post Hour \
count 500.000000 500.000000 500.000000 500.000000 500.000000
mean 123194.176000 1.880000 7.038000 4.150000 7.840000
std 16272.813214 0.852675 3.307936 2.030701 4.368589
min 81370.000000 1.000000 1.000000 1.000000 1.000000
25% 112676.000000 1.000000 4.000000 2.000000 3.000000
50% 129600.000000 2.000000 7.000000 4.000000 9.000000
75% 136393.000000 3.000000 10.000000 6.000000 11.000000
max 139441.000000 3.000000 12.000000 7.000000 23.000000

Paid Lifetime Post Total Reach Lifetime Post Total Impressions \


count 499.000000 500.00000 5.000000e+02
mean 0.278557 13903.36000 2.958595e+04
std 0.448739 22740.78789 7.680325e+04
min 0.000000 238.00000 5.700000e+02
25% 0.000000 3315.00000 5.694750e+03
50% 0.000000 5281.00000 9.051000e+03
75% 1.000000 13168.00000 2.208550e+04
max 1.000000 180480.00000 1.110282e+06

Lifetime Engaged Users Lifetime Post Consumers \


count 500.000000 500.000000
mean 920.344000 798.772000
std 985.016636 882.505013
min 9.000000 9.000000
25% 393.750000 332.500000
50% 625.500000 551.500000
75% 1062.000000 955.500000
max 11452.000000 11328.000000

Lifetime Post Consumptions \


count 500.000000
mean 1415.130000
std 2000.594118
min 9.000000
25% 509.250000
50% 851.000000
75% 1463.000000
max 19779.000000

Lifetime Post Impressions by people who have liked your Page \


count 5.000000e+02
mean 1.676638e+04
std 5.979102e+04
min 5.670000e+02
25% 3.969750e+03
50% 6.255500e+03
75% 1.486050e+04
max 1.107833e+06

Lifetime Post reach by people who like your Page \


count 500.000000
mean 6585.488000
std 7682.009405
min 236.000000
25% 2181.500000
50% 3417.000000
75% 7989.000000
max 51456.000000
Lifetime People who have liked your Page and engaged with your post \
count 500.000000
mean 609.986000
std 612.725618
min 9.000000
25% 291.000000
50% 412.000000
75% 656.250000
max 4376.000000

comment like share Total Interactions


count 500.00000 499.000000 496.000000 500.000000
mean 7.48200 177.945892 27.266129 212.120000
std 21.18091 323.398742 42.613292 380.233118
min 0.00000 0.000000 0.000000 0.000000
25% 1.00000 56.500000 10.000000 71.000000
50% 3.00000 101.000000 19.000000 123.500000
75% 7.00000 187.500000 32.250000 228.500000
max 372.00000 5172.000000 790.000000 6334.000000

In [ ]:

You might also like