Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas continues update csv

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

pandas continues update csv

In [1]: df = pd.read_csv('foo.csv', index_col=0)

In [2]: df
Out[2]:
   A  B  C
0  1  2  3
1  4  5  6

In [3]: df + 6
Out[3]:
    A   B   C
0   7   8   9
1  10  11  12

In [4]: with open('foo.csv', 'a') as f:
             (df + 6).to_csv(f, header=False)
Comment

PREVIOUS NEXT
Code Example
Python :: how to check if a column exists before alter the table 
Python :: indentation error in python atom editor 
Python :: find prime numbers in a given range for big input python 
Python :: add vertical line to horizontal graph 
Python :: conversion of int to a specified base number 
Python :: Read large SAS file ilarger than memory n Python 
Python :: axes turn of axis matplotlb 
Python :: flask request file upload to dropbox 
Python :: how to accept invalidfileexception in python 
Python :: test api register user 
Python :: convert a column to camel case in python 
Python :: how to make a series in python alternating between + and - 
Python :: mechanize python XE #25 
Python :: python find matching string regardless of case 
Python :: django rest DjangoModelPermissions include get 
Python :: inline_ternary(if)_condition 
Python :: le %s 
Python :: filter all columns in pandas 
Python :: install requests-html modlule click on the link to learn more about requests-html 
Python :: get weather data from weather underground 
Python :: FizzBuzz in Python Using itertools 
Python :: insertion sort algorithm in descending order 
Python :: Command to install Voluptuous Python Library 
Python :: foreach on sysargv 
Python :: Example of importing module in python 
Python :: selenium emojis 
Python :: generate pycryptodome salt 
Python :: Broadcasting with NumPy Arrays Single dimension array Example 
Python :: conmbination in python 
Python :: Python NumPy concatenate Function Example when axis equal to none 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =