I want to ask, how do you append data in csv, but determine the rows and columns yourself? maybe someone has an example?

            Asked
            
        
        
            Active
            
        
            Viewed 42 times
        
    0
            
            
         
    
    
        CodeMonkey
        
- 22,825
- 4
- 35
- 75
 
    
    
        519M4
        
- 17
- 4
- 
                    1Hi, please read this https://stackoverflow.com/help/minimal-reproducible-example and this https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples to improve your question. – Be Chiller Too Aug 17 '21 at 15:20
- 
                    Please share your code. Have you tried the `csv` library? – James Geddes Aug 17 '21 at 15:24
- 
                    A `csv` is a text file. If you open the file in append mode, you can write any text to it. Whether the result can be read by a regular csv-reader is another matter. I'm not sure what your display is? excel? – hpaulj Aug 17 '21 at 15:37
- 
                    What do you mean by "but determine the rows and columns yourself?" how do you want to determine the rows and columns? – Aug 17 '21 at 16:28
1 Answers
0
            
            
        There is df.loc:
df = pd.DataFrame([[111, 'Hi'], ['Hello', 222], [333, 'Ahoy']],
     columns=['Number', 'String'])
print(df)
    Number  String
0   111     Hi
1   Hello   222
2   333     Ahoy
# set row 1, column 'Number' to 222
df.loc[1, 'Number'] = 222
# set row 1, column 'String' to Hello
df.loc[1, 'String'] = 'Hello'
print('\n', df)
    Number  String
0   111     Hi
1   222     Hello
2   333     Ahoy
Unless it is a minor correction there are probably better ways.
 
    
    
        MDR
        
- 2,610
- 1
- 8
- 18