Python|熊猫 dataframe.info()
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas dataframe.info()函数用于获取数据帧的简明摘要。在对数据进行探索性分析时,它非常方便。为了快速了解数据集,我们使用 dataframe.info()函数。
Syntax: DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None)
Parameters :
verbose : Whether to print the full summary. None follows the display.max_info_columns setting. True or False overrides the display.max_info_columns setting.
buf : writable buffer, defaults to sys.stdout
max_cols : Determines whether full summary or short summary is printed. None follows the display.max_info_columns setting.
memory_usage : Specifies whether total memory usage of the DataFrame elements (including index) should be displayed. None follows the display.memory_usage setting. True or False overrides the display.memory_usage setting. A value of ‘deep’ is equivalent of True, with deep introspection. Memory usage is shown in human-readable units (base-2 representation).
null_counts : Whether to show the non-null counts. If None, then only show if the frame is smaller than max_info_rows and max_info_columns. If True, always show counts. If False, never show counts.
有关代码中使用的 CSV 文件的链接,请单击此处
示例 #1:使用 info()函数打印数据帧的完整摘要。
Python3
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Print the dataframe
df
Python3
# to print the full summary
df.info()
Python3
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Print the short summary of the
# dataframe by setting verbose = False
df.info(verbose = False)
Python3
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Print the full summary of the dataframe
# with null count excluded
df.info(verbose = True, null_counts = False)
让我们打印数据框的完整摘要。
Python3
# to print the full summary
df.info()
输出 :
正如我们在输出中看到的,摘要包括所有列及其数据类型的列表以及每列中非空值的数量。我们还为索引轴提供了 rangeindex 的值。示例 #2:使用 info()函数打印数据帧的简短摘要
注意:为了打印简短的摘要,我们可以使用详细参数并将其设置为 False。
Python3
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Print the short summary of the
# dataframe by setting verbose = False
df.info(verbose = False)
输出 :
正如我们在输出中看到的那样,摘要非常简洁明了。当我们在数据框中有 1000 个属性时,它会很有帮助。示例 #3:使用 info()函数打印数据帧的完整摘要并排除空计数。
注意:为了打印完整的摘要,排除空计数,我们可以使用空计数参数并将其设置为 false。
Python3
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Print the full summary of the dataframe
# with null count excluded
df.info(verbose = True, null_counts = False)
输出 :
正如我们在输出中看到的那样,摘要已满,但不包括空计数。