Read csv with python pandas

Read csv file with python

・ Python ・ Sqlite3 ・ Pandas

python


import sqlite3
import pandas as pd

df = pd.read_csv('{csv file path}', encoding='shift-jis') 
db_name = 'sample.db'  #Create db
conn = sqlite3.connect(db_name)  #Connect to db
df.to_sql('class_table', conn, if_exists='replace')  #Convert information that captures csv to sql
c = conn.cursor()
query = 'SELECT * FROM class_table'
result = c.execute(query)
c.fetchall()  #Get all

for row in result:  #Get one by one
  print(row)

for vert in range(2, 10):  #Get columns in order
  vert += 1
  for side in range(0, 4):
    print(df.loc[vert, side])
    side += 1

conn.close()  #db disconnect

Recommended Posts

Read csv with python pandas
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Read CSV file with python (Download & parse CSV file)
Read CSV file: pandas
Csv tinkering with python
Read Python csv file
Read CSV and analyze with Pandas and Seaborn
How to read a CSV file with Python 2/3
Read JSON with Python and output as CSV
[Python] How to read excel file with pandas
[Python] Change dtype with pandas
Write to csv with Python
Download csv file with python
Read json data with python
Read and format a csv file mixed with comma tabs with Python pandas
How to convert JSON file to CSV file with Python Pandas
[Python] How to deal with pandas read_html read error
Make a CSV formatting tool with Python Pandas PyInstaller
[Python] A memo to write CSV vertically with Pandas
Process csv data with python (count processing using pandas)
[Python] Loading csv files using pandas
Make apache log csv with python
[Python] Write to csv file with Python
Output to csv file with Python
[Python] Join two tables with pandas
[python] Read information with Redmine API
Handle Excel CSV files with Python
1. Statistics learned with Python 1-1. Basic statistics (Pandas)
Read files in parallel with Python
Reading and writing CSV with Python
Read fbx from python with cinema4d
Excel aggregation with Python pandas Part 1
[Python] Format when to_csv with pandas
[Python] Read the csv file and display the figure with matplotlib
How to read an Excel file (.xlsx) with Pandas [Python]
[Python] Read Japanese csv with pandas without garbled characters (and extract columns written in Japanese)
FizzBuzz with Python3
Scraping with Python
My pandas (python)
Load csv with duplicate columns in pandas
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Read pandas data
[C] [python] Read with AquesTalk on Linux
Play with 2016-Python
AES256 with python
Let's read the RINEX file with Python ①
Tested with Python
Read and write csv files with numpy
python starts with ()
Excel aggregation with Python pandas Part 2 Variadic
with syntax (Python)
Read Python csv and export to txt
Bingo with python
[Python] Read images with OpenCV (for beginners)
Zundokokiyoshi with python
[Part1] Scraping with Python → Organize to csv!
Csv in python