相关文章推荐
刚毅的红金鱼  ·  CAST and CONVERT ...·  1 周前    · 
犯傻的黄豆  ·  Branches API | GitLab ...·  1 周前    · 
会搭讪的饭盒  ·  博士申请 | ...·  1 年前    · 
热情的登山鞋  ·  linux ...·  2 年前    · 
温暖的凉茶  ·  使用 Razor 語法 (C#) | ...·  2 年前    · 
心软的红金鱼  ·  asp.net - C#: The ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams infy = get_history(symbol='INFY', start = start, end = end) infy.index = pd.to_datetime(infy.index) infy.head() infy_volume = infy.groupby(infy['Date'].dt.year).reset_index().Volume.sum().

"Error showed as Date", but Infy_volume should be a multi-index series with two levels of index - Year and Month

You have Date column as index so use infy.groupby(infy.index.year).Volume.sum().reset_index() Abhi Sep 15, 2018 at 5:26

Here you have the date column as index so use

infy.groupby(infy.index.year).Volume.sum().reset_index()

If you want to groupby with year and month use

infy_volume = infy.groupby([infy.index.year, infy.index.month]).Volume.sum()
infy_volume.index = infy_volume.index.rename('Month', level=1)
print(infy_volume)
# infy_volume.reset_index()
                infy.groupby([infy.index.year, infy.index.month]).volume.sum() is getting an error "Duplicated level name: "Date", assigned to level 1, is already used for level 0 ".
– sk jainmiah
                Sep 15, 2018 at 6:27
                same error bro " Duplicated level name: "Date", assigned to level 1, is already used for level 0."
– sk jainmiah
                Sep 15, 2018 at 6:36
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.