Python Forum
Append Multiple CSV files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Append Multiple CSV files
#1
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
Reply
#2
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'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Import multiple CSV files into pandas Krayna 0 1,724 May-20-2021, 04:56 PM
Last Post: Krayna
  Loading multiple JSON files to create a csv 0LI5A3A 0 2,113 Jun-28-2020, 10:35 PM
Last Post: 0LI5A3A
  How to extract different data groups from multiple CSV files using python Rafiz 3 3,255 Jun-04-2019, 05:20 PM
Last Post: jefsummers
  Grab columns from multiple files, combine into one jon0852 0 2,026 Feb-12-2019, 02:53 AM
Last Post: jon0852
  Concatenate multiple csv files Oscarca 1 3,073 Nov-05-2018, 11:18 AM
Last Post: Larz60+
  read multiple .xlsx files and text files in a directory BNB 11 25,730 Jun-07-2017, 07:42 AM
Last Post: BNB
  Read CSV Files with multiple headers into Python DataFrame UGuntupalli 12 26,829 Jan-26-2017, 03:07 PM
Last Post: UGuntupalli

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020