import pandas as pd # 创建一个示例数据帧 data = {'Name': ['Tom', 'Nick', 'John'], 'Age': [28, 32, 25], 'City': ['New York', 'Paris', 'London']} df = pd.DataFrame(data) # 获取行号 row_numbers = df.index.tolist() print("行号:", row_numbers) # 获取列号 column...
nopython=True, cache=True) def custom_mean_jitted(x): return (x * x).mean() In [4]: %time out = rolling_df.apply(custom_mean, raw=True) CPU times: user 3.57 s, sys: 43.8 ms, total: 3.61 s Wall time: 3.57 s
行列既可以使用索引名称也可以使用表示位置的整数 df1 = df.ix["x"...Part 3:布尔操作 获取某一列中值满足特定条件的行 对整体DataFrame进行判断,不符合的则将其对应值置为NaN df2 = df[df.a > 3] print("\ndf2= \n", df2...Part 4:获取单个值 使用at[行,列]或者iat[行,列]或者get_value(行...
df['A'] df[['A', 'B']] df['A'][0] df.loc[:,['A','B']] df.loc[:,'A':'C'] df.loc[0,'A'] df.loc[0:10,['A','C']] 通过位置获取: df.iloc[3] df.iloc[3,3] df.iloc[0:3,4:6] df.iloc[1:5,:] 通过布尔值过滤: df[df['A']>0] df[df['A'].isin([1...
df.to_excel('test_xlsx.xlsx',index=False)# 保存为ison文件 df.to_json('test_json.txt')3. 查看数据信息 3.1 查看前n行 3.2 查看后n行 3.3 查看行数和列数 3.4 查看列索引 3.5 查看行索引 3.6 查看索引、数据类型和内存信息 3.7 查看数值型列的汇总统计 3.8 查看每一列的唯一值和计数...
iloc[i]['test'] != 1: df1.iloc[i]['test'] = 0 下标循环是通过循环一个下标数列,通过iloc去不断get数据,这个方法是新手最常用的但也是最慢的,在测试例子中大概需要21.9s。 方法2:Iterrows循环(速度等级: ) i = 0 for ind, row in df.iterrows(): if row['test'] != 1: df1.iloc[i][...
>>> df_excel = pd.read_excel('data/table.xlsx') #xls或xlsx格式,需要安装xlrd包 1. 2. 3. 2、写入文件 >>> df.to_csv('data/new_table.csv') # csv格式 >>> df.to_csv('data/new_table.csv', index=False) # 保存时除去行索引 ...
# Quick examples of get the number of rows # Example 1: Get the row count # Using len(df.index) rows_count = len(df.index) # Example 2: Get count of rows # Using len(df.axes[]) rows_count = len(df.axes[0]) # Example 3:Get count of rows ...
df[['A', 'B']] df['A'][0] df[0:10][['A', 'C']] df.loc[:,['A','B']] df.loc[:,'A':'C'] df.loc[0,'A'] df.loc[0:10,['A','C']] 通过位置获取: df.iloc[3] df.iloc[3,3] df.iloc[0:3,4:6]
df_fintech = df_text[df_text['业务一级分类']=="金融科技"] 2、所在行内容是割裂的 先转成str格式再用contains筛选 1 df_fintech = df_text[df_text['业务一级分类'].str.contains("金融科技")] 3、筛选出列值属于某个范围内的行,用isin ...