Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # импортируем библиотеки
- import pandas as pd
- from sqlalchemy import create_engine
- # Выставляем некоторые опции
- pd.set_option('display.max_colwidth', None)
- db_config = {'user': 'praktikum_student', # имя пользователя
- 'pwd': 'Sdf4$2;d-d30pp', # пароль
- 'host': 'rc1b-wcoijxj3yxfsf3fs.mdb.yandexcloud.net',
- 'port': 6432, # порт подключения
- 'db': 'data-analyst-zen-project-db'} # название базы данных
- connection_string = 'postgresql://{}:{}@{}:{}/{}'.format(db_config['user'],
- db_config['pwd'],
- db_config['host'],
- db_config['port'],
- db_config['db'])
- engine = create_engine(connection_string)
- query = ''' SELECT *
- FROM dash_visits
- '''
- dash_visits = pd.io.sql.read_sql(query, con = engine)
- dash_visits
- dash_visits.info()
- dash_visits['item_topic'].unique()
- dash_visits['source_topic'].unique()
- dash_visits['age_segment'].unique()
- # Выгрузим датафрейм в CSV-файл
- dash_visits.to_csv('dash_visits.csv', sep='\t', encoding='utf-8', index=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement