1 回答

TA貢獻1820條經驗 獲得超10個贊
當DataFrame.info
打印出XXX to YYY
索引中的信息時,它只是打印出第一個索引值的值到最后一個索引值的值。如果您的索引不是單調的(可以使用 輕松檢查df.index.is_monotonic
),則這不對應于完整范圍。
負責此操作的代碼是Index._summary
,很明顯,它在總結時只是查看第一個值[0]
和最后一個值[-1]
def _summary(self, name=None) -> str_t:
? ? """
? ? Return a summarized representation.
? ? Parameters
? ? ----------
? ? name : str
? ? ? ? name to use in the summary representation
? ? Returns
? ? -------
? ? String with a summarized representation of the index
? ? """
? ? if len(self) > 0:
? ? ? ? head = self[0]
? ? ? ? if hasattr(head, "format") and not isinstance(head, str):
? ? ? ? ? ? head = head.format()
? ? ? ? tail = self[-1]
? ? ? ? if hasattr(tail, "format") and not isinstance(tail, str):
? ? ? ? ? ? tail = tail.format()
? ? ? ? index_summary = f", {head} to {tail}"
? ? else:
? ? ? ? index_summary = ""
這是一個簡單的例子:
import pandas as pd
df = pd.DataFrame(data=[1,1,1], index=pd.to_datetime(['2010-01-01', '2012-01-01', '2011-01-01']))
df.info()
#<class 'pandas.core.frame.DataFrame'>
#DatetimeIndex: 3 entries, 2010-01-01 to 2011-01-01
#...
sort如果您想在查看信息之前了解完整的索引:
df.sort_index().info()
#<class 'pandas.core.frame.DataFrame'>
#DatetimeIndex: 3 entries, 2010-01-01 to 2012-01-01
#...
- 1 回答
- 0 關注
- 156 瀏覽
添加回答
舉報