Padas学习笔记

创建数据表

设置列名,以及类型

all_data = pd.DataFrame(data=None, columns=['lon', 'lat', 'time', 'rank', 'wight', 'day'])
all_data['lon'] = all_data['lon'].astype('float')
all_data['lat'] = all_data['lat'].astype('float')
all_data['time'] = all_data['time'].astype('string')
all_data['rank'] = all_data['rank'].astype('int')
all_data['wight'] = all_data['wight'].astype('float')
all_data['day'] = all_data['day'].astype('int')

若要指定数据,一定要注意字典里的数据应为列表

df = pd.DataFrame(data={'lon': [row['lon']], 'lat': [row['lat']], 'time': [row['time']], 'rank': [1],'wight': [0], 'day': [0]})

遍历数据表

index为行号,row返回一行的引用,当修改row时,原数据表的内容也一起修改

for index, row in day_higMidPos.iterrows():

总的

# 判断一个值是否在某一列中存在
# Replace 'column_name' with the name of the column you want to check and 'specified_value' with the value you want to check for
df['column_name'].isin(['specified_value'])

# 使用两个条件进行筛选
# Replace 'column1_name' with the name of the first column you want to filter and 'specified_value1' with the value you want to filter for in the first column
# Replace 'column2_name' with the name of the second column you want to filter and 'specified_value2' with the value you want to filter for in the second column
df_filtered = df[(df['column1_name'] == 'specified_value1') & (df['column2_name'] == 'specified_value2')]

# 在一列中,删除值大于等于5的行
# Replace 'column_name' with the name of the column you want to filter and '5' with the value you want to filter for
df = df.drop(df[df['column_name'] >= 5].index, axis=0)

# 对某一列数据求和
# Replace 'column_name' with the name of the column you want to sum
sum_of_column = df['column_name'].sum()

# 将某一列赋值为同一个值
# Replace 'column_name' with the name of the column you want to set and 'specified_value' with the value you want to set the column to
df['column_name'] = 'specified_value'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值