Home > Mobile >  'str' object is not callable in csv import pandas
'str' object is not callable in csv import pandas

Time:09-01

I am trying to import CSV in Google Colab using pandas but failed

I have attached code here:

import pandas as pd 
labels_df=pd.read_csv(r'.\data\train_labels.csv')
#labels_df=pd.read_csv(path2csv)
labels_df.head()

This is error:

TypeError                                 Traceback (most recent call last)
<ipython-input-26-b4781c7a6dff> in <module>
      1 import pandas as pd
      2 
----> 3 labels_df=pd.read_csv(r'.\data\train_labels.csv')
      4 #labels_df=pd.read_csv(path2csv)
      5 labels_df.head()

TypeError: 'str' object is not callable

Any idea?

CodePudding user response:

'''

import pandas as pd 

labels_df=pd.read_csv("../dataAws/train_labels.csv")
labels_df.head()

''' I restarted kernel and it worked

CodePudding user response:

The following code works on a new Colab notebook:

import pandas as pd 
labels_df = pd.read_csv('./sample_data/california_housing_train.csv')
labels_df.head()

Notice the path variable uses forward slash '/' and not backslash '\' but using a backslash should produce a FileNotFoundError and not TypeError so I'm guessing there is some other problem not shown in your question.

  • Related