0

For a current project, I am among others converting data of a Pandas DataFrame.

When calling the line df['date'] = pd.to_datetime(df['date']), I am receiving the error TypeError: 'method' object is not subscriptable.

I have in this context already checked for some approached relating e.g. to missing parentheses but could not find a matching solution yet. Is there any smart tweak to make this run?

The code section is shown below:

import string
import json
import pandas as pd

# Loading and normalising the input file
file = open("sp500.json", "r")
data = json.load(file)
df = pd.json_normalize(data)
df = pd.DataFrame().fillna

# Datetime conversion
df['date'] = pd.to_datetime(df['date'])
4
  • please provide example of your data. it's hard to tell where the problem with converting data, with no idea how the data looks like Commented Jul 13, 2020 at 18:11
  • 2
    pd.DataFrame.fillna() Commented Jul 13, 2020 at 18:11
  • I'm voting to close this as a type or not reproducible given the () are missing in the fillna() function. Commented Jul 13, 2020 at 18:13
  • Thanks for your input. This amendment is however yielding the following error TypeError: fillna() missing 1 required positional argument: 'self' Commented Jul 13, 2020 at 18:32

1 Answer 1

1

Instead of

df = pd.DataFrame().fillna

You should have called the fillna method.

df = df.fillna(method='bfill')
Sign up to request clarification or add additional context in comments.

1 Comment

Good idea - when using this line, I am however receiving the following error ValueError: Must specify a fill 'value' or 'method'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.