由于在处理结构性数据的时候经常会读取本地形如:.xls、xlsx、csv等的数据。所以今天就花了点时间来总结一下利用python读取csv数据并且转换为dataframe的数据框架。话不多说,直接附代码:

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)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
猜你喜欢
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-01-30
  • 2022-12-23
  • 2021-11-27
相关资源
相似解决方案