CSV input, output với Pandas

Tính Phạm
1 min readMar 9, 2020

--

Import thư viện numpy và pandas, (np và pd là 2 alias)

import numpy as np
import pandas as pd

CSV input

Sử dụng read_csv để đọc file csv có tên là example.csv

df = pd.read_csv('example.csv')

CSV output

  • Tạo dictionary có tên data
  • Tạo DataFrame có tên df từ data ban đầu
data = {'a':[1,2,3,4],
'b':[4,5,6,7],
'c':[8,9,10,11]}
df = pd.DataFrame(data)

Xuất data Frame ra csv có tên example, không đánh index

df.to_csv('example.csv'',index=False)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Tính Phạm
Tính Phạm

Written by Tính Phạm

càng đơn giản càng tốt

No responses yet

Write a response