How can I fix a problem about ‘the list is not callable’

I am going to make a DataFrame but it had error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-28-3f0c40c312c9> in <module>
      9 #
     10 #
---> 11 df3 = pd.DataFrame([noteSeries, weekdaySeries]) #
     12 print(df3)

TypeError: 'list' object is not callable
noteSeries = pd.Series(["C", "D", "E", "F", "G", "A", "B"],
    index=[1, 2, 3, 4, 5, 6, 7])

weekdaySeries = pd.Series(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
    index=[1, 2, 3, 4, 5, 6, 7])

df3 = pd.DataFrame([noteSeries, weekdaySeries]) # 
print(df3)

Answer

This works for me as it is, with a couple of changes according to PEP8:

import pandas as pd


noteSeries = pd.Series(
    ["C", "D", "E", "F", "G", "A", "B"],
    index=[1, 2, 3, 4, 5, 6, 7])

weekdaySeries = pd.Series(
    ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
    index=[1, 2, 3, 4, 5, 6, 7])

df3 = pd.DataFrame([noteSeries, weekdaySeries])
print(df3)

Try updating your version of pandas using the command line:

pip install --upgrade pandas

or

python -m pip install --upgrade pandas

If that doesn’t fix it, then it’s possible in your previous bit of code you have overwritten pd.DataFrame like this:

pd.DataFrame = [1, 3, 5]

What this would do is it would make the DataFrame function into a normal list, which you then can’t call as a function any more.

Leave a Reply

Your email address will not be published. Required fields are marked *