TGStat
TGStat
Type to search
Advanced channel search
  • flag English
    Site language
    flag Russian flag English flag Uzbek
  • Sign In
  • Catalog
    Channels and groups catalog Regional compilations Thematic compilations Платные каналы Search for channels
    Add a channel/group
  • Ratings
    Rating of channels Rating of groups Posts rating
    Ratings of brands and people
  • Analytics
  • Search by posts
  • Telegram monitoring
  • Promotion
    Advertising through Yandex Business Advertising in channels through TGStat Agency Advertising on TGStat.ru website
PytStart | Программирование на Python

26 Sep, 15:24

Open in Telegram Share Report

🖥 Как превратить CSV в словарь Python

CSV часто используется для хранения таблиц. А загрузить его в Python можно буквально за несколько строк 👇


import csv

with open("users.csv", encoding="utf-8") as file:
users = list(csv.DictReader(file))

print(users[0]) # Alex

users.csv выглядит так:

name,age,city
Alex,25,Moscow
Anna,22,Kazan

💡 А дальше с данными можно работать как с обычными словарями:

for user in users:
if int(user["age"]) >= 25:
print(user["name"])

🔥 Полезно для:
— обработки таблиц
— импорта данных
— небольших скриптов
— автоматизации отчётов

516 0 9 3
Catalog
Channels and groups catalog Channels compilations Search for channels Add a channel/group
Ratings
Rating of Telegram channels Rating of Telegram groups Posts rating Ratings of brands and people
API
API statistics Search API of posts API Callback
Our channels
@TGStat @TGStat_Chat @telepulse @TGStatAPI
Read
Академия TGStat Telegram Research 2019 Telegram Research 2021 Telegram Research 2023
Contacts
Справочный центр Support Email Jobs
Miscellaneous
Terms and conditions Privacy policy Public offer
Our bots
@TGStat_Bot @SearcheeBot @TGAlertsBot @tg_analytics_bot @TGStatChatBot