随笔分类 - pandas数据分析
摘要:Every time you want to save a Pandas DataFrame to an Excel, you may call this function: import os def save_excel_sheet(df, filepath, sheetname, index=
阅读全文
摘要:jupyter中显示的DataFrame过长时会自动换行(print()显示方式)或自动省略(单元格最后一行直接显示),在一些情况下看上去不是很方便,可调节显示参数如下: import pandas as pd pd.set_option('display.width', 500) #设置整体宽度
阅读全文
摘要:An example of converting a Pandas dataframe to an Excel file with column formats using Pandas and XlsxWriter. It isn’t possible to format any cells th
阅读全文
摘要:Python中运用openpyxl包对Excel表格进行美化,包括字体样式调整、单元格对齐方式调整、单元格边框调整、单元格背景颜色调整、行高和列宽调整。 使用的Python中openpyxl包的版本为3.0.5 先看实际美化前后的效果对比 详细的开发代码如下,代码当中对关键信息进行了说明。 复制代码
阅读全文
摘要:In [2]: dfOut[2]: A B0 p1 11 p1 22 p3 33 p2 4 In [3]: df.loc[df['B'] == 3, 'A']Out[3]:2 p3Name: A, dtype: object In [4]: df.loc[df['B'] == 3, 'A'].ilo
阅读全文
摘要:pandas dataframe 修改列名的方法 加之rename函数,用字典的形式替换式的修改, df.rename(columns={'a':'A',"b":"B"}) df 三、obj[‘col’] = value 方法直接对 DataFrame 直接赋值即可 in [6]: data['d'
阅读全文
摘要:本文主要是在pandas中如何对字符串进行切分。我们考虑一下下面的应用场景。 这个是我们的数据集(data),可以看到,数据集中某一列(name)是某个行业的分类。各个行业之间用符号 ‘|’分割。我们要把用每个‘|’进行分割的内容抽取出来。pandas有个一步到到位的方法,非常方便。 import
阅读全文
摘要:you can use this code to open (test.xlsx) file and modify A1 cell and then save it with a new name import openpyxl xfile = openpyxl.load_workbook('tes
阅读全文
摘要:3 You can use pandas.ExcelFile to have a peek at the sheet names, then select the sheets to keep with any method (here your regex), finally load with
阅读全文
摘要:In this article, we will discuss getting the ceil and floor values of the Pandas Dataframe. First, Let’s create a dataframe. Example: Python3 # import
阅读全文
摘要:在操作pandas的DataFrame的时候,常常会遇到某些列是字符串,某一些列是数值的情况,如果直接使用df_obj.apply(sum)往往会出错使用如下方式即可对其中某一列进行求和 dataf_test1['diff'].sum() // diff为要求和的列
阅读全文
摘要:原本的数据类型凌乱不按照日期排序,不利于数据分析 import pandas as pd#读取文件数据df = pd.read_csv('clientinfo-截止2019-12-20:00:00.csv')#按照列值排序data=df.sort_values(by="createtime" , a
阅读全文
摘要:如何用python中pandas模块在csv文件中添加表头 话不多说,直接上代码: python 复制代码 import pandas as pd df = pd.read_csv('tf.csv',header=None,names=['a','b','c','d','e','f','g','h'
阅读全文
摘要:DataFrame.iat 按整数位置访问行/列对的单个值。 与iloc类似,两者都提供基于整数的查找。如果只需要在DataFrame或Series中获取或设置一个值,则使用iat。 Raises: 当整数位置超出界限时抛出IndexError 例子: >>> df = pd.DataFrame([
阅读全文
摘要:保留原顺序。 old_list = [2, 3, 4, 5, 1, 2, 3] new_list = [] for i in old_list: if i not in new_list: new_list.append(i) print(new_list) # [2, 3, 4, 5, 1] 用字
阅读全文
摘要:1.删除重复的数据 df.drop_duplicates();默认删除完全一样的行数据。 2.删除NaN数据 df.dropna() ;默认删除掉行数据,只要一行中有NaN; 3.pandas读取excel空白单元格默认设置修改 pandas读取excel表格空值为NaN;用df.fillna没有效
阅读全文
摘要:Example #1: Use Series.str.contains a () function to find if a pattern is present in the strings of the underlying data in the given series object. Py
阅读全文
摘要:In this article, we will discuss how to loop or Iterate overall or certain columns of a DataFrame? There are various methods to achieve this task.Let’
阅读全文
摘要:为了保存来自pandas dataframe的csv文件,我尝试了以下方法: res.to_csv('seq_test.fa',header= False, index= False, sep = '\t', quoting = csv.QUOTE_NONE) 复制 这给出了以下错误:need to
阅读全文
摘要:import pandas as pd import csv f = open(r'C:/Users/will/Desktop/log-2023-05-22.log',encoding='utf-8') data = pd.read_csv(f,sep='\n',header=None) for i
阅读全文