0

For a current project, I am planning to clean a Pandas DataFrame off its Null values. For this purpose, I want to use Pandas.DataFrame.fillna, which is apparently a solid soliton for data cleanups.

When running the below code, I am however receiving the following error AttributeError: module 'pandas' has no attribute 'df'. I tried several options to rewrite the line df = pd.df().fillna, none of which changed the outcome.

Is there any smart tweak to get this running?

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.df().fillna
0

1 Answer 1

2

When you load the file to the pandas - in your code the data variable is a DataFrame instance. However, you made a typo.

df = pd.json_normalize(data)
df = df.fillna()
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the input. This result is yielding ValueError: Must specify a fill 'value' or 'method'.. The approach df = pd.DataFrame().fillna seems to work however
@M.S. pandas.pydata.org/pandas-docs/stable/reference/api/… here are the docs. You need to set a few variables. If that works out please upvote my answer and accept it :) df = pd.DataFrame().fillna(value = ' DataFrame'should work out
@M.S. as it working, can you please accept my answer and upvote me? :))

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.