python - 如何在熊猫中正确添加图形
问题描述
当我在熊猫中绘制不同的数据集时,它没有正确显示所需的图形,而是显示了一个不正确的线性图。我应该如何解决这个问题?
import pandas as pd
import matplotlib.pyplot as plt
#cleaning the csv file
fh=pd.read_csv('Documents/ads/2019 T1_12.csv',skiprows=[0,1,3,9,15,21,27,30,31,32,33,34,35])
fh=fh.drop('Total',axis=1)
fh=fh.drop('Others', axis=1)
#plotting
plt.plot(fh['Year'],fh['Germany'])
plt.plot(fh['Year'], fh['USA'])
plt.ylabel('Number of Emigrants', fontsize=17)
plt.xlabel('Years', fontsize=17)
fh.index
fh.head()
解决方案
看起来USA
的 dtype 是对象,导致线性图和混乱的 ylabels。
您可能需要添加thousands=','
到read_csv
通话中。
之后,请参阅 Quang Hong 的答案以获得更好的可视化提示。
推荐阅读
- android - Android改造无法解析响应标头中的所有数据
- kotlin - Kotlin listOf 函数:参数的最大数量是多少?
- java - JAVA匹配字符串数组到双数组
- python - 带有 PySimpleGUI 的 Python 中的日历位置
- python - Python:如何导入 Excel 单元格的显示(格式化)值而不是实际值
- grails - Grails 域的常用 beforeUpdate 方法
- eclipse - Eclipse远程跟踪分支突然全部丢失
- javascript - 即使期望为真,javascript 正则表达式也会返回假。没有 sj 错误
- javascript - 根 id 中没有呈现任何内容
- php - 比较并显示查询结果mysql