Python Forum
Dataframe not appending correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dataframe not appending correctly
#3
(Jul-10-2019, 12:17 AM)scidam Wrote: There are lots of questions here: What are B, D, F in line #6? what means 'xxx.hdf', why did you use key[0:-4], are all of your keys have length 5? Did you use pd.concat somewhere in your code? Should 'xxx.hdf'.format(key[0:-4]) be something like '{}.hdf'.format(key)?

B, D, F are separate arrays that were concatenated and appended to an array for each feature. 'A', 'C' and 'E' are the columns names. Sorry for the vague names but just for the sake of preserving the data confidentiality.

xxx.hdf is the file name that I want to give for each of the dataframe created and this name is derived from the key value in the dictionary. It is supposed to be df.to_hdf('C:\...\....\{}.hdf'.format(key[0:-4]),mode='w', key='df'). key[0:-4] allows me to extract only the key name upto before the last 4 characters (to remove '.csv') in the end of the key value. So originally the key values are filea.csv, fileb.csv and filec.csv

I hope this explains.

I think what is happening is the arrays that are getting appended are not getting removed so I do not know if I will be doing the right thing to add the code below after saving the dataframe:

del(B)
del(D)
del(F)
or if there is a more efficient way to reset these arrays?

alright, i have solved my problem. I placed creating the empty arrays in the beginning of the code to be after the first for loop instead of having it before the first for loop so that every time it loops, a new set of empty arrays is created. I guess I just needed a break and your questions to think through! Thanks!
Reply


Messages In This Thread
RE: Dataframe not appending correctly - by scidam - Jul-10-2019, 12:17 AM
RE: Dataframe not appending correctly - by python_newbie09 - Jul-10-2019, 07:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing results within a list and appending to pandas dataframe Aryagm 1 2,357 Dec-17-2020, 01:08 PM
Last Post: palladium

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020