Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas continues update csv with exception

def appendDFToCSV_void(df, csvFilePath, sep=","):
    import os
    if not os.path.isfile(csvFilePath):
        df.to_csv(csvFilePath, mode='a', index=False, sep=sep)
    elif len(df.columns) != len(pd.read_csv(csvFilePath, nrows=1, sep=sep).columns):
        raise Exception("Columns do not match!! Dataframe has " + str(len(df.columns)) + " columns. CSV file has " + str(len(pd.read_csv(csvFilePath, nrows=1, sep=sep).columns)) + " columns.")
    elif not (df.columns == pd.read_csv(csvFilePath, nrows=1, sep=sep).columns).all():
        raise Exception("Columns and column order of dataframe and csv file do not match!!")
    else:
        df.to_csv(csvFilePath, mode='a', index=False, sep=sep, header=False)
Comment

PREVIOUS NEXT
Code Example
Python :: duplicate characters in a string python 
Python :: fake-useragent proxy webscraping browser change 
Python :: python multiprocessing queu empty error 
Python :: differentate derivative differentation 
Python :: np.ma.filled 
Python :: Spansk dansk 
Python :: get all methods of an instance 
Python :: flask request file push request(uploadedfile= request.file) uploadedfile.read() 
Python :: mongoengine ObjectIdField 
Python :: bs.newtag() inner html 
Python :: poppler not in path 
Python :: python counting subfolders on specific level 
Python :: mechanize python XE #26 
Python :: pandas add missing rows from another dataframe 
Python :: divisibility by 13 in python 
Python :: how to catch chunkedencodingerror 
Python :: AI code for diagnosing diseases 
Python :: Jupyter to access jupyter notebook on virtualbox guest through browser in windows host 
Python :: how to draw tony stark sketch in python 
Python :: python nmap api functionality 
Python :: FizzBuzz in Python Using Lambda 
Python :: print numbers 1 to 10 using recursion in python 
Python :: Command to import the Schema interface from voluptuous 
Python :: droping columns 
Python :: NO OF CLASSES IN PAVIA UNIV DATASET 
Python :: how to move mouse by detected face and eye using opencv 
Python :: ouvrir fichier txt python et le lire 
Python :: Broadcasting with NumPy Arrays Example 
Python :: python read file with class 
Python :: Python NumPy stack Function Syntax 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =