0

I like to fill the null values in a column with a formel based on other columns:

data['datacqtr'].fillna(data['datadate'].dt.year.apply(str) + str('Q')+data['datadate'].dt.quarter.astype(str))

Can you see where the problem is with my Code? Because there are some nulll values after this code.

My Dataframe:

datadate | datacqtr 2002-02-28|2002Q1

Dataacqtr stands for the Quarter. And sometimes I have datadate but no datacqtr (Quarter). So I like to fill up the colmn datacqtr based on the colmn datadate.

roganjosh
  • 12,594
  • 4
  • 29
  • 46
pythoo
  • 27
  • 7
  • 1
    This is a pretty fundamental misunderstanding of the python language. You're not calling `fillna()`, you're reassigning it – roganjosh Dec 26 '19 at 11:57
  • 4
    Ugh, please make sure you actually post correct code. The only thing I can think of is that you haven't used `inplace=True`. You need to get these things correct with a [mcve] before posting... it's a single line of code, there's no real excuse to not get it correct – roganjosh Dec 26 '19 at 12:00
  • yes this is the solution. inplace=true is missing. Thank you – pythoo Dec 26 '19 at 12:03
  • 2
    might be worth going through all the answers in the linked dupe , especially [this](https://stackoverflow.com/a/59242208/9840637) – anky Dec 26 '19 at 12:22

2 Answers2

1

fillna() is a method on a dataframe -- you pass arguments to it. In the snippet above it looks like you are assigning something to it instead. It would help to get a sample of the dataframe you're working with and what your expected result is.

navneethc
  • 1,234
  • 8
  • 17
0

inplace = true is missing. Got the solution.

pythoo
  • 27
  • 7