程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Pandas various tosses

編輯:Python

I can't think of a good topic , Just make do with it , Anyway pandas Various tossing data

data = pd.read_csv('new_jn_data.csv')
data['date'] = data['ctime'].str.split(' ',1).apply(lambda x:x[0])
data['date'] = data['date'].str.replace('/','-')
data['date'] = pd.to_datetime(data['date'])
data['data'] = data['data'].str.replace(',','').astype(float)
data['start_time']=data['ctime'].str.split(' ',1).apply(lambda x:x[1].split(':',1)[0]).astype(int)
# For the convenience of sorting sequence , According to the first cell From small to large , Then arrange by date , Are in increasing order
data = data[['date','start_time','cell','enodeb','data','sub_net','ne']].sort_values(by='date').sort_values(by='cell')
# Index rearrangement
data = data.reset_index(drop=True)
# Save the data
# data.to_csv('new_jn_data_with_nan.csv',index=0)
# Remove containing nan The line of .
data2 = data.dropna(axis=0,how='any')
# Save the data , But the index is still data The index of , If you want to rebuild the index, you can :data2 = data.dropna(axis=0,how='any').reset_index(drop=True)
# data2.to_csv('new_jn_data_exclude_nan.csv',index=0)

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved