pandas處理數(shù)據(jù)筆記

x1=[12,435,23]
x2=[21,42,452]
x3 = map(lambda x,y:x-y,x1,x2)
print x3
x3_1 = map(lambda x:x**2,x3)
print x3_1
x3_sum = sum(x3_1)
print x3_sum

計(jì)算航向角與航跡角的偏差,對(duì)DataFrame的列進(jìn)行計(jì)算處理

import pandas as pd
import math
import matplotlib as mpl  
mpl.use('Agg')  
import matplotlib.pyplot as plt

ans=pd.read_table(r'/home/wanghan/AMAP_intern/dataAnalysis/Yaw and Flight Path comparision/trajectory5961-5985.txt',sep=',')

ans=ans[(ans['time_stamp'] > 5961) & (ans['time_stamp'] < 5985) & (ans['index'] % 60 == 1)]
ans.reset_index().to_csv(r'./Yaw and Flight Path comparision/down_sample_trajectory5961-5985.txt',index=False)

yaw_angle = ans['yaw(deg)']
yaw_angle = yaw_angle.values
s1 = ans.x.diff() //得到的是series類型
s2 = ans.y.diff()
s3 = s1/s2

a1= s3.values
a2 = map(lambda x:math.atan(x),a1) 
a3 = map(lambda x:math.degrees(x)+180, a2)

bias = yaw_angle - a3
bias_ = pd.DataFrame(bias)
bias_.columns = ['angle_bias']

plt.figure()
plt.title("angle_bias")
# plt.xlabel("time")
plt.ylabel("degree")
plt.plot(bias_.index,bias_['angle_bias'])
plt.show()
plt.savefig('3.png')

給yaw這一列都加上一個(gè)數(shù)

df1=pd.read_table(r'D:\Kevin\Alibaba_summer\Amap_Intern\test1.txt',sep=',')
df1.loc[:,'yaw(deg)'] = df1.loc[:,'yaw(deg)'] + 0.333
df1.to_csv(r'D:\Kevin\Alibaba_summer\Amap_Intern\test2.txt', sep=',',index=False)

根據(jù)時(shí)間這一列,把其他列按照時(shí)間相減 .set_index('根據(jù)的列名')

df1 = pd.read_table(r'D:\Ubuntu_disk\test1.txt', sep = ',')
df2 = pd.read_table(r'D:\Ubuntu_disk\test2.txt', sep = ',')
ans = df1.set_index('time_stamp') - df2.set_index('time_stamp')
ans = ans.reset_index()

多張圖畫在同一張圖上

python Matplotlib 可視化總結(jié)歸納(二) 繪制多個(gè)圖像單獨(dú)顯示&多個(gè)函數(shù)繪制于一張圖

對(duì)某一列的某一個(gè)值按照條件進(jìn)行處理

[dataframe 針對(duì)列條件賦值]

#常規(guī)方式
import pandas as pd

df = pd.DataFrame({'one':['a', 'a', 'b', 'c'], 'two':[3,1,2,3], 'three':['C','B','C','A']})
print(df)

df.loc[df['two']==2, 'one']='x' #修改列"one"的值,推薦使用.loc
print(df)

df.one[df.two==2]='x'
print(df)

DataFrame選取偶數(shù)行和奇數(shù)行

#%% 
import pandas as pd
import numpy as np
#%%
np.random.seed(1071)
df = pd.DataFrame(
        np.random.randint(1, 30, (7, 2)), columns=list('AB'), 
        index=range(1, 8)
)
#
#    A   B
#1  28  22
#2  17  13
#3  10   3
#4  19  25
#5   2   6
#6  22  27
#7  28  26

df.iloc[::2] # 奇數(shù)行
#    A   B
#1  28  22
#3  10   3
#5   2   6
#7  28  26

df.iloc[1::2] # 偶數(shù)行
#    A   B
#2  17  13
#4  19  25
#6  22  27

Python pandas.DataFrame.cumsum函數(shù)方法的使用

https://www.cjavapy.com/article/376/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容