Java如何在String.format中显示百分号%
如果要显示 %
,我们需要在前面再加一个 %
,做为转义用。
1 | String.format("%d%%", 100); |
这时才会正确显示 100%
。
如果要显示 %
,我们需要在前面再加一个 %
,做为转义用。
1 | String.format("%d%%", 100); |
这时才会正确显示 100%
。
当标签文本很长时,或者是某维度的数据列表长度很长时,都会造成标签的重叠覆盖。
解决方法有以下几种。我们使用的数据如下:
1 | import pandas as pd |
查看画布默认大小
1 | plt.rcParams['figure.figsize'] |
我们把画布拉长一倍,设置 figsize 参数。
1 | fig, axs = plt.subplots(figsize=(12, 4)) |
拉长以后,bar 的宽度也变大了。
由于 x 轴的数据太多了,还是有覆盖现象。
1 | fig, axs = plt.subplots() |
1 | fig, axs = plt.subplots() |
目前比较好的解决方案可能是标签旋转,再适当的放大x轴。
1 | fig, axs = plt.subplots(figsize=(12, 4)) |
创建 DataFrame 的几种方法。
1 | class pandas.DataFrame(data=None, index: Optional[Collection] = None, columns: Optional[Collection] = None, |
data 参数可以是:ndarray (structured or homogeneous), Iterable, dict, or DataFrame.
Dict can contain Series, arrays, constants, or list-like objects.
1 | import pandas as pd |
看看创建的 DataFrame 元素的类型。
1 | df.dtypes |
如果要修改类型
1 | import numpy as np |
1 | df3 = pd.DataFrame({'col1': pd.Series([1, 2]), 'col2': pd.Series([3, 4])}) |
1 | df4 = pd.DataFrame([{'col1': 1, 'col2': 3}, {'col1': 2, 'col2': 4}]) |
column 为父字典的 key,index 为子字典的 key。
1 | df4 = pd.DataFrame({'col1': {'idx1': 1, 'idx2': 2}, 'col2': {'idx1': 3, 'idx2': 4}}) |
1 | df5 = pd.DataFrame([[1, 3], [2, 4]]) |
当然,也可以自定义 index 和 column
1 | df6 = pd.DataFrame([[1, 3], [2, 4]], index=['a', 'b'], columns=['c1', 'c2']) |