【发布时间】:2020-10-10 08:30:55
【问题描述】:
我有一个 .csv,如下图所示:
我想创建 4 个数据框,我目前正在使用 .iloc 进行创建
import pandas as pd
enter code here
file_path='/file/path/name.csv'
df_main=pd.read_csv(file_path)
enter code here
df_global=df_main.iloc[:3,:]
df_mkt_a=df_main.iloc[6:9,:]
df_mkt_b=df_main.iloc[12:15,:]
df_mkt_c=df_main.iloc[18:21,:]
但这可能会在添加/删除行时遇到问题,并且非常不灵活。
还有什么更 Pythonic 的方式来读取这些数据?
【问题讨论】: