Creating multiple dataframes with a loop

前端 未结 3 810
闹比i
闹比i 2021-02-04 22:27

This undoubtedly reflects lack of knowledge on my part, but I can\'t find anything online to help. I am very new to programming. I want to load 6 csvs and do a few things to the

3条回答
  •  走了就别回头了
    2021-02-04 23:09

    A dictionary can store them too

    import pandas as pd
    from pprint import pprint
    
    files = ('doms_stats201610051.csv', 'doms_stats201610052.csv')
    dfsdic = {}
    dfs = ('df1', 'df2')
    for df, file in zip(dfs, files):
      dfsdic[df] = pd.read_csv(file)
      print(dfsdic[df].shape)
      print(dfsdic[df].dtypes)
      print(list(dfsdic[df]))
    
    print(dfsdic['df1'].shape)
    print(dfsdic['df2'].shape)
    

提交回复
热议问题