1

Note: I saw all related issues to group by output, and I changed my code accordingly but did not get the required output.

I created test data set after group by with one of the column in the data set. Then I tried below to get desired output.

fd = pd.read_csv("C:/......\Test.csv")

coder_gr = fd.groupby(["CIQ"])
print(coder_gr.first())

for x, y in coder_gr:
    y.columns = pd.CategoricalIndex(y.columns)
    y.columns = y.columns.add_categories(["Duplicate"])
    y["Duplicate"] = y.Date.duplicated()

"""also tried with below code:"""

for x, y in coder_gr:
    y.assign(Duplicate = y.Date.duplicated().values, index=y.index)

But getting below empty output or error (Setting with Copy Warning):

enter image description here enter image description here

enter image description here

  • Please read https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples, and then provide the input, as well as the expected output, **as text** in your question. – Roy2012 Jul 11 '20 at 15:10

1 Answers1

0

In the third line coder_gr.reset_index() should do the job.

SevenOfNine
  • 630
  • 1
  • 6
  • 25
  • 1
    After using the above code, I am getting error message as : AttributeError: 'DataFrameGroupBy' object has no attribute 'reset_index' @SevenOfNine – surya ambati Jul 11 '20 at 15:18