Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grab columns from multiple files, combine into one
I have some files stored in a cloud storage bucket and each file contains different variables. What I would like to develop is a function whereby I simply enter in the variables I am interested in and run the function to create a master data set with only those columns/variables. The function iterates through the files and when it finds one of the variable/column names entered as input in the function in one of the files, it grabs that column(s) and joins it to a master dataframe. Below is what I have so far. Any help in developing this further would be very much appreciated.

from import file_io

files = [o.key for o in storage.Objects(bucket_name, '', '')]
def get_my_data(list1):
  files = [o.key for o in storage.Objects(bucket_name, '', '')]
  for l in list1:
    for f in files:
      file1="gs://bucket_name/%s" % f
      with file_io.FileIO(file1, 'r') as f:
        columns = pd.read_csv(f, nrows=1)
        if l in columns:
          print file1, data[l]
          #append desired column to our new df
get_my_data(['var1', 'var2', 'var3'])


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Extracting specific columns in an array uthongam 1 154 Dec-07-2018, 06:06 PM
Last Post: ichabod801
  Concatenate multiple csv files Oscarca 1 259 Nov-05-2018, 11:18 AM
Last Post: Larz60+
  HOw define the colors for two columns? Jack_Sparrow 3 453 Jun-15-2018, 06:46 PM
Last Post: snippsat
  Trying to clean the selected columns paulgureghian 5 550 Jun-08-2018, 10:08 PM
Last Post: volcano63
  comparing two columns two different files in pandas nuncio 0 331 Jun-06-2018, 01:04 PM
Last Post: nuncio
  Dropping all rows of multiple columns after the max of one cell Thunberd 2 376 Jun-01-2018, 10:18 PM
Last Post: Thunberd
  subtruction of columns in pandas garikhgh0 3 515 May-14-2018, 10:31 AM
Last Post: volcano63
  Question from beginners: how to combine 2 columns Jack_Sparrow 1 521 May-12-2018, 04:18 PM
Last Post: woooee
  How to read specified columns Raj 0 368 May-08-2018, 11:59 AM
Last Post: Raj
  Get rows with same value from dataframe of particular columns angelwings 1 454 Apr-11-2018, 02:40 AM
Last Post: scidam

Forum Jump:

Users browsing this thread: 1 Guest(s)