this dataset train.csv has 200column, named as var_0,var_1 ....... var_199

for i in range(200):
    c= "var_" + str(i)

the above line is for creating variable names using loop

    b= project.c.describe()

AttributeError                            Traceback (most recent call last)
<ipython-input-46-b90b661d528b> in <module>
      2     c= "var_" + str(i)
      3     #print(c)
----> 4     b= project.c.describe()

~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5177             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5178                 return self[name]
-> 5179             return object.__getattribute__(self, name)
   5181     def __setattr__(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'c'
  • $\begingroup$ you have object c in for, not attribute for df.... $\endgroup$
    – quester
    Oct 26 '19 at 20:39

You are calling it as if c was an attribute, while it is a column name; it should be:


and you don't need to assign it to a variable.


You have two issues with your code.

1st problem You overwrite the variable c in every loop your for does

for i in range(200):
    c= "var_" + str(i)

>> print(c)
>> "var_200"

What you want is:

c = ["var_" + str(i) for i in range(200)]


c = []
for i in range(200):
    c.append("var_" + str(i))

2nd problem The c is a python variable. Not a column. What you need to do is to use it like this


What you did would work only if you had a dataframe with the column name "c". For example

    a    b    c
0   1    2    3
1   3    1    5

You would be able to use project.c and would print

0   3
1   5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.