Python Forum

Full Version: Append Multiple CSV files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I have to append multiple csv files while using pandas. I have to convert the data into desired datatype and then append but when i am doing this, i am getting an TypeError i.e.

Error:
TypeError: convert_data() missing 1 required positional argument: 'data'
I am using below code :

import pandas as pd
def convert_data (data):
    for i in data:
        df[i].dropna(inplace=True)
        df[i]["CONSUMER_NO"] = df[i]["CONSUMER_NO"].astype(int)
        df[i]["BUPC"] = df[i]["BUPC"].astype(int)
        df[i]["DTC"] = df[i]["DTC"].astype(int)
        df[i]["AREA"] = df[i]["AREA"].astype(str)
        df[i]["ZONE"] = df[i]["AREA"].astype(str)
        df[i]["METER_STATUS"] = df[i]["METER_STATUS"].astype(str)
        return;

df0 = pd.read_csv("E:\\test10.csv",header=0,skiprows=0)
df1 = pd.read_csv("E:\\test11.csv",header=0,skiprows=0)
df2 = pd.read_csv("E:\\test12.csv",header=0,skiprows=0)

data = [df0,df1,df2]
#data_before = data.dtypes

convert_data()

data.append(df0,df1,df2)
data
Many thanks,

Nidhesh
On line #2 function is defined with parameter data
On line #20 function is called without argument

It is clearly stated in error message: convert_data() missing 1 required positional argument: 'data'
(Jul-03-2019, 11:45 AM)perfringo Wrote: [ -> ]On line #2 function is defined with parameter data
On line #20 function is called without argument

It is clearly stated in error message: convert_data() missing 1 required positional argument: 'data'

I got you. Thanks. But if i have to convert the data of all the csv files do i have to type convert function for each and every file ?

Thanks