Rabu, 11 Mei 2022

ETL Extract Transform Load

  • Complete the transform_avg_rating() function by grouping by the course_id column, and taking the mean of the rating column.
  • Use extract_rating_data() to extract raw ratings data. It takes in as argument the database engine db_engines.
  • Use transform_avg_rating() on the raw rating data you've extracted.
  • Mencari kesamaan antar user 1 2 3 berdasarkan rating yang di input di sistem

Now that you have a grasp of what's happening in the datacamp_application database, let's go ahead and write up a query for that database.

The goal is to get a feeling for the data in this exercise. You'll get the rating data for three sample users and then use a predefined helper function, print_user_comparison(), to compare the sets of course ids these users rated.

  • Complete the connection URI. The database is called datacamp_application. The host is localhost with port 5432. The username is repl and the password is password.
  • Select the ratings of users with id: 438718163 and 8770.
  • Fill in print_user_comparison() with the three users you selected.

# Complete the connection URI

connection_uri = "postgresql://repl:password@localhost:5432/datacamp_application" 
db_engine = sqlalchemy.create_engine(connection_uri)

# Get user with id 4387
user1 = pd.read_sql("SELECT * FROM rating WHERE user_id=4387", db_engine)

# Get user with id 18163
user2 = pd.read_sql("SELECT * FROM rating WHERE user_id=18163", db_engine)

# Get user with id 8770
user3 = pd.read_sql("SELECT * FROM rating WHERE user_id=8770", db_engine)

# Use the helper function to compare the 3 users
print_user_comparison(user1, user2, user3)


Course id overlap between users:

================================ User 1 and User 2 overlap: {32, 96, 36, 6, 7, 44, 95} User 1 and User 3 overlap: set() User 2 and User 3 overlap: set()


Mencari Average Rating

In this exercise, you'll complete a transformation function transform_avg_rating() that aggregates the rating data using the pandas DataFrame's .groupby() method. The goal is to get a DataFrame with two columns, a course id and its average rating:

course_idavg_rating
1234.72
1114.62

In this exercise, you'll complete this transformation function, and apply it on raw rating data extracted via the helper function extract_rating_data() which extracts course ratings from the rating table.


  • Complete the transform_avg_rating() function by grouping by the course_id column, and taking the mean of the rating column.
  • Use extract_rating_data() to extract raw ratings data. It takes in as argument the database engine db_engines.
  • Use transform_avg_rating() on the raw rating data you've extracted

# Complete the transformation function
def transform_avg_rating(rating_data):
    # Group by course_id and extract average rating per course
    avg_rating = rating_data.groupby('course_id').rating.mean()
    # Return sorted average ratings per course
    sort_rating = avg_rating.sort_values(ascending=False).reset_index()
    return sort_rating

# Extract the rating data into a DataFrame    
rating_data = extract_rating_data(db_engines)

# Use transform_avg_rating on the extracted data and print results
avg_rating_data = transform_avg_rating(rating_data)
print(avg_rating_data) 

course_id rating 0 46 4.800000 1 23 4.800000 2 96 4.692765 3 56 4.661765 4 24 4.653061 .. ... ... 94 54 4.238095 95 92 4.222222 96 29 4.208333 97 17 4.147059 98 42 4.107570



Tidak ada komentar:

Posting Komentar

Label

Do it Yourself (42) Sepeda (33) Motorcycle (30) soluna (30) GoPro (28) Roda4 (23) Jual (20) Travelling (19) nouvo (19) jupiter (17) Jasa (11) office (11) mutasi (10) racing (9) Engineering (8) King (8) balap (8) gokart (8) vw (6) Dad (5) pompa (5) roadrace (5) Centrifugal Pump (4) Motor (4) championship (4) karting (4) qatar (4) roadbike (4) tamiya (4) balap motor (3) indoprix (3) kart (3) motogp (3) mp4 (3) mp5 (3) strava (3) yamaha (3) Atoz (2) Dinamo (2) PC (2) crank (2) cycling (2) laptop (2) politik (2) rider (2) sentul (2) shimano (2) windows (2) 105 (1) 5tp (1) API 610 (1) API 610. API 682 (1) Atomic Tuned (1) BRT (1) Caterpillar (1) Chassis (1) Continuous (1) Control Station (1) Cummins (1) Diesel Engine (1) Engine (1) Ergonomis (1) HFE (1) HMI (1) HT2 (1) Human Factor Engineering (1) Hyperdash (1) IEC (1) ISO 8528 (1) Light Dash (1) MS (1) MTU (1) Mini4WD (1) NFPA 20 (1) OSHA (1) Prime (1) RD (1) RPM (1) STO (1) Side Damper (1) Super 2 (1) Super FM (1) Super II (1) Tinggi (1) Torque Tuned (1) VFD (1) air (1) aki (1) arab (1) avg (1) avometer (1) balance bike (1) ban bocor (1) ban sepeda (1) bapak2 (1) berat badan (1) bersepeda (1) best time (1) bike (1) bmi (1) bobot (1) casey stoner (1) circuit (1) claris (1) couples (1) curve (1) dBA (1) deli (1) deli-tire (1) delitire (1) deore (1) derawan (1) dive (1) diy (1) duraace (1) effort (1) egypt (1) elektrik motor (1) fast (1) fire (1) firepump (1) friend (1) geography (1) gram (1) grand fondo (1) grandfondo (1) gravel (1) gravel bike (1) happy (1) hearth (1) height (1) heist (1) hollow (1) hope (1) hubungan antar negara (1) ilmu korek (1) indonesia (1) instalasi (1) irag (1) iran (1) jogja (1) jorge martin (1) kakabhan (1) kalimantan (1) kebisingan (1) kecepatan (1) kenda (1) lap time (1) long cage (1) lose (1) love (1) luas air (1) luas tanah (1) lusail (1) maratua (1) material (1) mekanik (1) michelin (1) middle east (1) mio (1) mobil (1) modifikasi (1) motorbalap (1) mp3 (1) mtb (1) multimeter (1) muslim (1) nanjak (1) negara (1) negara paling besar (1) noise (1) oil (1) oil&gas (1) optimal (1) pemilihan (1) performance (1) pitstop (1) point tertinggi (1) polished (1) polygon (1) porting (1) ppe (1) pressure (1) qkc (1) racer (1) ram (1) rear deralier (1) resort (1) result (1) rotating (1) rotating engineer (1) rumah (1) safety (1) sanwa (1) schwalbe (1) seleksi material (1) self reflecting (1) self talk (1) sentul circuit (1) setting (1) shock (1) shockbreaker (1) short cage (1) snorkle (1) sokbreaker (1) sound (1) speed (1) sponsor (1) sport (1) sram (1) standing (1) steel (1) strider (1) tambal (1) tambal ban (1) tempat jadian (1) tidak merusak ban (1) time (1) tiptop (1) tire (1) travel buddies (1) tuning (1) ultegra (1) velg sepeda (1) visit (1) weight (1) win (1) window (1) winner (1) worry (1)