python read csv convert dataframe

Preface:

Since the terrain is often present as read when processing structured data: .xls, xlsx, csv like data. So today spent a little time to sum up the use of python csv data read and converted into a data frame dataframe. Man of few words said, directly attached Code:

import csv
from pandas.core.frame import DataFrame
import pandas as pd

tmp_lst = []
with open('filename_path.csv', 'r') as f:
    reader = csv.reader(f)
    for row in reader:
        tmp_lst.append(row)
df = pd.DataFrame(tmp_lst[1:], columns=tmp_lst[0]) 
print(df)

 

Guess you like

Origin www.cnblogs.com/shierlou-123/p/11619876.html