左侧图表(带图例的图表)源自df_2,右侧图表源自df_1.
但是,我无法将这两个图并排分享y轴.
这是我目前绘制的方式:
df_1[target_cols].plot(kind='barh', x='LABEL', stacked=True, legend=False)
df_2[target_cols].plot(kind='barh', x='LABEL', stacked=True).invert_xaxis()
plt.show()
Run Code Online (Sandbox Code Playgroud)
代码将在两个不同的"画布"中产生两个图.
df_2)的y轴标签?任何建议将不胜感激.谢谢.
需要一些有关如何检索所选文件夹的目录路径并将其设置在 LineEdit 上的建议。
如果我单击工具按钮(红圈内的按钮),则会弹出一个对话框窗口。然后我们可以导航以选择所需的文件夹。我希望一旦用户单击“选择文件夹”,我就可以将所选文件夹的路径(以字符串形式)传递到按钮旁边的 lineEdit 框。但是,我无法弄清楚如何做到这一点。到目前为止,这是我的代码:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_TestQFileDialog(object):
def _open_file_dialog(self): # a function to open the dialog window
result = str(QtWidgets.QFileDialog.getExistingDirectory())
print(result)
return result
def setupUi(self, TestQFileDialog):
TestQFileDialog.setObjectName("TestQFileDialog")
TestQFileDialog.resize(240, 320)
self.toolButtonOpenDialog = QtWidgets.QToolButton(TestQFileDialog)
self.toolButtonOpenDialog.setGeometry(QtCore.QRect(210, 10, 25, 19))
self.toolButtonOpenDialog.setObjectName("toolButtonOpenDialog")
directory = self.toolButtonOpenDialog.clicked.connect(self._open_file_dialog)
self.lineEdit = QtWidgets.QLineEdit(TestQFileDialog)
self.lineEdit.setEnabled(False)
self.lineEdit.setGeometry(QtCore.QRect(10, 10, 191, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setText('{}'.format(directory))
self.retranslateUi(TestQFileDialog)
QtCore.QMetaObject.connectSlotsByName(TestQFileDialog)
def retranslateUi(self, TestQFileDialog):
_translate = QtCore.QCoreApplication.translate
TestQFileDialog.setWindowTitle(_translate("TestQFileDialog", "Dialog"))
self.toolButtonOpenDialog.setText(_translate("TestQFileDialog", "..."))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv) …Run Code Online (Sandbox Code Playgroud) 我完全糊涂了.可能我错过了pandasAPI 的更新.
所以我有这个excel文件
在Pandas 0.18.1我没有遇到在读取和解析该文件的任何问题.我使用了以下代码,
import pandas as pd
fname = 'SAMPLE_EXCEL_CAUSING_ERROR_IN_PANDAS_0_19_UP.xlsx'
pd.read_excel(fname, 'Sheet1', header=[0,1], index=[0,1])
Run Code Online (Sandbox Code Playgroud)
它返回了我想要的东西.
最近,我更新了我的软件包,现在我pandas已经进入了version 0.20.1.但是,当我尝试使用相同的excel文件执行相同的代码时,它返回了一个错误.这是错误消息:ValueError: Length of new names must be 1, got 2.
任何线索我在哪里错过了新的API read_excel?我完全糊涂了.是否有任何解决方法来读取excel带有MultiIndex列的文件?我的真实数据有3级索引而不是2级索引.非常感谢任何建议.
PS我无法降级,0.18.1因为我的用户正在使用0.20.1
UPDATE
奇怪的是,如果我设置header为header=[1,2]然后它没有抛出任何错误消息.但是,我的指数错误.仍在努力解决此问题.