python pandas 查看数据集列和行

#查看数据集中的列
import pandas
#列用什么分割  --sep
df = pandas.read_csv('./gapminder.tsv',sep='\t')

#获取列
country_df = df['country']
print(country_df)

#显示前5行
print(country_df.head())
#现在是最后五行
print(country_df.tail())

#三列前5行
subset = df[['country','continent','year']]
print(subset.head())

#查看数据集中的行
import pandas
#列用什么分割  --sep
df = pandas.read_csv('./gapminder.tsv',sep='\t')

#获得行数据  loc  iloc

#获得第一行  把名字放到左边  值放到右边
#print(df.loc[0])
#获得15行
print(df.loc[15])

#行数 1704
#number_of_rows = df.shape[0]
#print(type(df.loc[number_of_rows -1]))
#print(type(df.head()))

#print('------------')

#获取 2 4 5 行
print(df.loc[[2,4,5]])
#print(df.iloc[-1])

你可能感兴趣的:(Python,数据分析)