python - Having trouble with x axis date in line chart (pandas)
问题描述
This seems very simple and I am not sure why it's not working. It works fine when I use a stacked bar chart, but when I use a line chart the formatting is not correct (or something else is not working?). For example, the stacked barchart looks like
Very simple logic to create the above chart:
pivot_df = base_df.pivot(index='date', columns='column10', values='values')
pivot_df1 = pivot_df.fillna(0)
pivot_df1 = pivot_df1.astype(float)
pivot_df1 = pivot_df1.plot.bar(stacked=True, figsize=(10,7))
Now I am trying to create a line chart using the same base dataset (so same dates) but slightly different columns/values. I filter the dataset on one condition and remove a few columns (not sure if this is causing the issue?).
base_df1 = base_df[((base_df['filter_column'] == 'this'))]
base_df1 = base_df1[['date', 'column2', 'column3', 'column4']]
base_df1 = base_df1.fillna(0)
base_df1 = base_df1.astype(float)
base_df1_piv = base_df1.pivot_table(index='date',columns='column2', values = 'column3')
base_df1_piv.plot.line()
I feel like I am missing something very obvious? Any help is appreciated.
解决方案
推荐阅读
- x86 - _mm_sfence 内在函数和 SFENCE 指令之间有什么关系?
- python - AttributeError:模块'plotly'没有属性'plotly'
- powershell - 从 Powershell 脚本中提取 AST
- javascript - Particles.js 在 .html 文件中有效,但在 .ejs 文件中无效
- webhooks - 使用 webhook 在不和谐中更新角色时如何获取用户角色名称
- javascript - 如何使用 websocket 实现自动完成?
- ruby-on-rails - 覆盖为 json rails 5.2 时需要一组不同的数据
- android - 安全参数:无法解析符号“字符串”
- android - Android 数据绑定:有没有显示/隐藏包含标签的好方法?
- python - 如何将 sqlite 命令转换为 python-sqlite 命令