+ Reply to Thread
Results 1 to 4 of 4

Populating New Column in Pandas (Python)

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Populating New Column in Pandas (Python)

    Hi

    I am using the bellow code to combine some similar files in a directory

    Please Login or Register  to view this content.
    What I am stuck in is to add respective file name against each row of the dataframe
    I tried AllNames['File Name'] = f but it only prints the name of first file till the end of the Dataframe

    Any help would be greatly appreciated

    Best Regards

    Imran Bhatti
    Teach me Excel VBA

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Populating New Column in Pandas (Python)

    what do you mean by this?
    Quote Originally Posted by ImranBhatti View Post
    What I am stuck in is to add respective file name against each row of the dataframe
    AGAINST each row?

    Quote Originally Posted by ImranBhatti View Post
    I tried AllNames['File Name'] = f but it only prints the name of first file till the end of the Dataframe
    the usage of [] symbols in python is for array elements, if I'm not mistaken. or, a reference pointer by object name. what do you mean by it only prints the name of the first file ''TILL THE END OF THE DATAFRAME''?? TILL the end? I'm not understanding that.

    https://pandas.pydata.org/pandas-doc...ead_excel.html

    https://pandas.pydata.org/pandas-doc...DataFrame.html

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Populating New Column in Pandas (Python)

    Thanks vba_php for the review

    As you can see there is a loop through files, so I want the program to print f i.e. the file name in another column against each row of dataframe from which this row was taken.

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Populating New Column in Pandas (Python)

    we may be on different levels, in terms of our understanding and speaking of English. Unfortunately I'm not understanding this from you:
    Quote Originally Posted by ImranBhatti View Post
    Thanks vba_php for the so I want the program to print f i.e. the file name in another column against each row of dataframe from which this row was taken.
    AGAINST each row of the frame FROM which this row was taken?

    not following that. and perhaps that's because I haven't written Python in a while. I recognize the loop. Python is notorious for using minimal lines to write loops.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vba / python / api ?????
    By wherdzik in forum Excel General
    Replies: 0
    Last Post: 05-27-2020, 09:26 AM
  2. [SOLVED] Python Question
    By LiLi1 in forum The Water Cooler
    Replies: 3
    Last Post: 08-14-2019, 01:57 PM
  3. Python Question
    By LiLi1 in forum Tips and Tutorials
    Replies: 1
    Last Post: 08-13-2019, 11:10 PM
  4. Python
    By ImranBhatti in forum The Water Cooler
    Replies: 4
    Last Post: 09-28-2018, 07:41 AM
  5. VBA & Python
    By snb in forum The Water Cooler
    Replies: 2
    Last Post: 02-26-2018, 05:50 PM
  6. Python or VBA in excel
    By songhaegyo in forum The Water Cooler
    Replies: 49
    Last Post: 01-11-2018, 12:40 PM
  7. Excel and Python
    By davidlawrence in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2008, 08:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1