Home > database >  first argument must be an iterable of pandas objects, you passed an object of type "DataFrame&q
first argument must be an iterable of pandas objects, you passed an object of type "DataFrame&q

Time:04-27

import pandas as pd
import calendar
from datetime import datetime
data1 = pd.read_csv(train.csv")
data1['date']= data1.datetime.apply(lambda x : x.split()[0])
data1['hour']= data1.datetime.apply(lambda x : x.split()[1].split(":")[0])
data1["weekday"]= data1.date.apply(lambda dateString : calendar.day_name[datetime.strptime(dateString,"%m/%d/%Y").weekday()])
data1["month"]= data1.date.apply(lambda dateString : calendar.month_name[datetime.strptime(dateString,"%m/%d/%Y").month])
data1.to_csv("output1.csv")
bookings = data1.groupby('month')['Total_booking'].mean().sort_values(ascending=False)
bookings.to_csv("output2.csv")
from pandas import get_dummies
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
data1['holiday'] =  le.fit_transform(data1['holiday'])

newdata = pd.get_dummies(data,columns=['weekday','month','season','weather'])
data2 = pd.concat(newdata,axis=1)

newdata1 = data1.drop(['weekday','month','season','weather'],axis=1,inplace=true)
newdata1.to_csv('output/output3.csv')

           TypeError        Traceback (most recent call last)
  ~\AppData\Local\Temp/ipykernel_1496/4131473043.py in <module>
           5 
              6 newdata = pd.get_dummies(data1,columns=['weekday','month','season','weather'])
                ----> 7 data2 = pd.concat(newdata,axis=1)
              8 
                    9 newdata1 = data1.drop(['weekday','month','season','weather'],axis=1,inplace=true)

    ~\anaconda3\lib\site-packages\pandas\util\_decorators.py in 
       wrapper(*args, **kwargs)
       309                     stacklevel=stacklevel,
     310                 )
    --> 311             return func(*args, **kwargs)
      312 
      313         return wrapper

       ~\anaconda3\lib\site-packages\pandas\core\reshape\concat.py 
       in concat(objs, axis, join, ignore_index, keys, levels, 
       names, verify_integrity, sort, copy)
       292     ValueError: Indexes have overlapping values: ['a']
        293     """
       --> 294     op = _Concatenator(
        295         objs,
        296         axis=axis,

    ~\anaconda3\lib\site-packages\pandas\core\reshape\concat.py in 
   __init__(self, objs, axis, join, keys, levels, names, 
 ignore_index, verify_integrity, copy, sort)
      327     ):
       328         if isinstance(objs, (ABCSeries, ABCDataFrame, str)):
       --> 329             raise TypeError(
         330                 "first argument must be an iterable of pandas "
          331                 f'objects, you passed an object of type "{type(objs).__name__}"'

        TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame"

I am trying to save the new CSV file by dropping some values and changing the DateTime format....a little help...................... I DID RECTIFY THE ERRORS BUT NOW IT SHOWING THESE .......................................................

CodePudding user response:

You might have missed out on calling your dataset.

Try updating le.fit_transform('holiday') to le.fit_transform(data['holiday']) instead.

LabelEncoder.fit_transform() takes in an array-like parameter containing the target values and return the encoded labels.

CodePudding user response:

It seems you have two main errors.

1. LabelEncoder

This code of line is erroneous. fit_transform() is is not a class method, it is an instance method. This means that, first, you have to create an instance of the class.

You should add () like this to create and instance of the class:

le = LabelEncoder()

2. le.fit_transform

You should refererence to you dataframe (data1 in your case) like this:

le.fit_transform(data1['holiday'])
  • Related