pandas-处理csv常用命令

1.读取文件的前2列并导出

import pandas as pd

campaign_df = pd.read_csv('all.csv', sep='\t', encoding='gb18030')

campaign_df.head()

#查看第一列的相信信息
campaign_df.iloc[0]

#只看其中2列
df = campaign_df[['campaignId', 'campaignName']]

#导出
df.to_csv('tmp.csv', header=False, index=False)

2.对读取到pandas中的内容做遍历

import pandas as pd
campaign_df = pd.read_csv('all.csv', sep='\t', encoding='gb18030')
campaign_df.shape
campaign_df.head()
for i in range(campaign_df.shape[0]):
    tmp = campaign_df.iloc[i]
    print(tmp)
    print(tmp['campaignName'])
    break

你可能感兴趣的:(pythonn,python,数据挖掘,开发语言)