PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 28, 2022

[FIXED] How to add another value to a given row and column

 August 28, 2022     csv, dataframe, pandas, python     No comments   

Issue

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


Solution

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'


Answered By - Alireza
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing