Data loading

2022-06-15

import pandas as pd
import psycopg2.extras
from sqlalchemy import create_engine

conn = psycopg2.connect(host='192.168.55.115', user='aistudy', password='aistudy', dbname='2022_aistudy', port=30432)

engine = create_engine('postgresql://aistudy:aistudy@192.168.55.115:30432/2022_aistudy')
conn2 = engine.connect()

db_test = pd.read_sql_table('titanic', conn2)
## 2.1 Load the data from files into a single dataframe

pd.DataFrame(db_test)
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body homedest
0 1 1 Allen, Miss. Elisabeth Walton female 29 0 0 24160 211.3375 B5 S 2 ? St Louis, MO
1 1 1 Allison, Master. Hudson Trevor male 0.9167 1 2 113781 151.55 C22 C26 S 11 ? Montreal, PQ / Chesterville, ON
2 1 0 Allison, Miss. Helen Loraine female 2 1 2 113781 151.55 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
3 1 0 Allison, Mr. Hudson Joshua Creighton male 30 1 2 113781 151.55 C22 C26 S ? 135 Montreal, PQ / Chesterville, ON
4 1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25 1 2 113781 151.55 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1304 3 0 Zabour, Miss. Hileni female 14.5 1 0 2665 14.4542 ? C ? 328 ?
1305 3 0 Zabour, Miss. Thamine female ? 1 0 2665 14.4542 ? C ? ? ?
1306 3 0 Zakarian, Mr. Mapriededer male 26.5 0 0 2656 7.225 ? C ? 304 ?
1307 3 0 Zakarian, Mr. Ortin male 27 0 0 2670 7.225 ? C ? ? ?
1308 3 0 Zimmerman, Mr. Leo male 29 0 0 315082 7.875 ? S ? ? ?

1309 rows × 14 columns

## 2.2 DataFrame preview (show the first 10 rows)

engine = create_engine('postgresql://aistudy:aistudy@192.168.55.115:30432/2022_aistudy')
conn2 = engine.connect()
data = pd.read_sql_table('titanic', conn2)

db_test.head(10)
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body homedest
0 1 1 Allen, Miss. Elisabeth Walton female 29 0 0 24160 211.3375 B5 S 2 ? St Louis, MO
1 1 1 Allison, Master. Hudson Trevor male 0.9167 1 2 113781 151.55 C22 C26 S 11 ? Montreal, PQ / Chesterville, ON
2 1 0 Allison, Miss. Helen Loraine female 2 1 2 113781 151.55 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
3 1 0 Allison, Mr. Hudson Joshua Creighton male 30 1 2 113781 151.55 C22 C26 S ? 135 Montreal, PQ / Chesterville, ON
4 1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25 1 2 113781 151.55 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
5 1 1 Anderson, Mr. Harry male 48 0 0 19952 26.55 E12 S 3 ? New York, NY
6 1 1 Andrews, Miss. Kornelia Theodosia female 63 1 0 13502 77.9583 D7 S 10 ? Hudson, NY
7 1 0 Andrews, Mr. Thomas Jr male 39 0 0 112050 0 A36 S ? ? Belfast, NI
8 1 1 Appleton, Mrs. Edward Dale (Charlotte Lamson) female 53 2 0 11769 51.4792 C101 S D ? Bayside, Queens, NY
9 1 0 Artagaveytia, Mr. Ramon male 71 0 0 PC 17609 49.5042 ? C ? 22 Montevideo, Uruguay
## 2.3 Calculating columns and row size and display the result

db_test.shape
(1309, 14)
import pandas as pd

csv_test = pd.read_csv('C:/Users/ygjung/Documents/titanic-openml_01.csv')
## 2.1 Load the data from files into a single dataframe

pd.DataFrame(csv_test)
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body homedest
0 1 1 Allen, Miss. Elisabeth Walton female 29 0 0 24160 211.3375 B5 S 2 ? St Louis, MO
1 1 1 Allison, Master. Hudson Trevor male 0.9167 1 2 113781 151.5500 C22 C26 S 11 ? Montreal, PQ / Chesterville, ON
2 1 0 Allison, Miss. Helen Loraine female 2 1 2 113781 151.5500 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
3 1 0 Allison, Mr. Hudson Joshua Creighton male 30 1 2 113781 151.5500 C22 C26 S ? 135 Montreal, PQ / Chesterville, ON
4 1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25 1 2 113781 151.5500 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
995 3 0 Markoff, Mr. Marin male 35 0 0 349213 7.8958 ? C ? ? ?
996 3 0 Markun, Mr. Johann male 33 0 0 349257 7.8958 ? S ? ? ?
997 3 1 Masselmani, Mrs. Fatima female ? 0 0 2649 7.2250 ? C C ? ?
998 3 0 Matinoff, Mr. Nicola male ? 0 0 349255 7.8958 ? C ? ? ?
999 3 1 McCarthy, Miss. Catherine 'Katie' female ? 0 0 383123 7.7500 ? Q 15 16 ? ?

1000 rows × 14 columns

## 2.2 DataFrame preview (show the first 10 rows)

csv_test.head(10)
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body homedest
0 1 1 Allen, Miss. Elisabeth Walton female 29 0 0 24160 211.3375 B5 S 2 ? St Louis, MO
1 1 1 Allison, Master. Hudson Trevor male 0.9167 1 2 113781 151.5500 C22 C26 S 11 ? Montreal, PQ / Chesterville, ON
2 1 0 Allison, Miss. Helen Loraine female 2 1 2 113781 151.5500 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
3 1 0 Allison, Mr. Hudson Joshua Creighton male 30 1 2 113781 151.5500 C22 C26 S ? 135 Montreal, PQ / Chesterville, ON
4 1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25 1 2 113781 151.5500 C22 C26 S ? ? Montreal, PQ / Chesterville, ON
5 1 1 Anderson, Mr. Harry male 48 0 0 19952 26.5500 E12 S 3 ? New York, NY
6 1 1 Andrews, Miss. Kornelia Theodosia female 63 1 0 13502 77.9583 D7 S 10 ? Hudson, NY
7 1 0 Andrews, Mr. Thomas Jr male 39 0 0 112050 0.0000 A36 S ? ? Belfast, NI
8 1 1 Appleton, Mrs. Edward Dale (Charlotte Lamson) female 53 2 0 11769 51.4792 C101 S D ? Bayside, Queens, NY
9 1 0 Artagaveytia, Mr. Ramon male 71 0 0 PC 17609 49.5042 ? C ? 22 Montevideo, Uruguay
## 2.3 Calculating columns and row size and display the result

csv_test.shape
(1000, 14)

results matching ""

    No results matching ""

    99 other / uml

    04 react / JSX