Home > Net >  How to add another value to a given row and column
How to add another value to a given row and column

Time:06-20

I've been struggling with one problem for two days that I have with Python and the Pandas package. I am creating a dataframe with filtered data from another csv and then want to export it to csv again. However, I have a problem because I do not know how to add another value to a specific cell without removing the previous one so that it looks more or less like this in CSV. So that I could add this letter b to the second column and the first row where the letter a already exists

enter image description here

CodePudding user response:

You can use this code It edits all of the rows if you want else you want to edit just first row you can remove for loop and use i=0


for i in df.index:
  if df['B'][i].find('a')>=0:
    df['B'][i]  = ', b'




CodePudding user response:

df_10 = pd.DataFrame({'A': ['xx', '--- bios ---', 'yy', 'zz', '--- os ---'],'B': ['rat', '', 'winter', 'host','']})

I create such a data frame as add to column A and line 2, for example the value "new"

  • Related