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
  Selecting Few Columns from a dataframe Shivi_Bhatia 2 140 Mar-24-2019, 12:20 PM
Last Post: Shivi_Bhatia
  compare and modify columns in dataframe DionisiO 1 146 Feb-23-2019, 11:07 PM
Last Post: tiredAcademic
  Extracting specific columns in an array uthongam 1 228 Dec-07-2018, 06:06 PM
Last Post: ichabod801
  Concatenate multiple csv files Oscarca 1 329 Nov-05-2018, 11:18 AM
Last Post: Larz60+
  HOw define the colors for two columns? Jack_Sparrow 3 540 Jun-15-2018, 06:46 PM
Last Post: snippsat
  Trying to clean the selected columns paulgureghian 5 656 Jun-08-2018, 10:08 PM
Last Post: volcano63
  comparing two columns two different files in pandas nuncio 0 402 Jun-06-2018, 01:04 PM
Last Post: nuncio
  Dropping all rows of multiple columns after the max of one cell Thunberd 2 447 Jun-01-2018, 10:18 PM
Last Post: Thunberd
  subtruction of columns in pandas garikhgh0 3 606 May-14-2018, 10:31 AM
Last Post: volcano63
  Question from beginners: how to combine 2 columns Jack_Sparrow 1 606 May-12-2018, 04:18 PM
Last Post: woooee

Forum Jump:

Users browsing this thread: 1 Guest(s)