Tag: pandas

使用python从其他excel的值更改excel文件中的值

我有数据 id 30046 30049 30040 30046 接下来的胜利 id mail 30049 natusya_89_2009@mail.ru 30046 fresh_tea@mail.ru 30040 sedoi7072@mail.ru 我想从1文件更改ID从2 Excel的邮件。 欲望输出 id fresh_tea@mail.ru natusya_89_2009@mail.ru sedoi7072@mail.ru fresh_tea@mail.ru 我试试 for (id1, id2, mail) in zip(ids1, ids2, mails): if id1 == id2: ids1.replace(id1, mail)

大pandas阅读excel格式

在格式化后如何获得电子表格的值? 即时通讯工作与货币格式的电子表格 这例如: ITEM NAME UNIT PRICE item1 USD 99 item2 SGD 45 但“USD”和“SGD”这两个术语是使用excel的格式化function添加的,并且pandas的read_excel函数看不到这些术语。 我会得到的价值,但不是货币的名称。 我只能在电子表格上工作,因为我有各种各样的电子表格,大约有6-7张,我希望有一个pandas(或python)级别的解决scheme,而不是一个Excel级别的解决scheme。 多谢你们。 对丹尼尔来说,这就是我实现'xlrd'引擎的方式,它似乎没有做任何事情。 excel = pd.ExcelFile('itemlist.xlsx', sheetname=None) master = pd.DataFrame(None) for sheet in excel.sheet_names: df = pd.read_excel(excel,sheet,header=2, engine='xlrd') master=master.append(df)

合并Excel表单不工作的pythonpandas

我试图合并两个Excel表使用常见的提交的序列,但抛出一些错误。 我的程序如下: (user1_env)root@ubuntu:~/user1/test/compare_files# cat compare.py import pandas as pd source1_df = pd.read_excel('a.xlsx', sheetname='source1') source2_df = pd.read_excel('a.xlsx', sheetname='source2') joined_df = source1_df.join(source2_df, on='Serial') joined_df.to_excel('/root/user1/test/compare_files/result.xlsx') 得到错误如下: (user1_env)root@ubuntu:~/user1/test/compare_files# python3.5 compare.py Traceback (most recent call last): File "compare.py", line 5, in <module> joined_df = source1_df.join(source2_df, on='Serial') File "/home/user1/miniconda3/envs/user1_env/lib/python3.5/site-packages/pandas/core/frame.py", line 4385, in join rsuffix=rsuffix, sort=sort) File "/home/user1/miniconda3/envs/user1_env/lib/python3.5/site-packages/pandas/core/frame.py", line 4399, in _join_compat […]

对存储在两个单独文档中的坐标运行True / False语句

还是很新的这一切,所以任何帮助,build议等等,真的很感激。 下面是我的代码: import math import pandas file1 = pandas.read_excel('Book1.xlsx') file2 = pandas.read_excel('Book2.xlsx') file1['RA_diff'] = file2['RA'] – file1['RA'] file1['DEC_diff'] = file2['DEC'] – file1['DEC'] dist = file1.apply(lambda row: math.hypot(row['RA_diff'], row['DEC_diff']), axis=1) if dist.values >= 5: print False elif dist.values <= 5: print True, dist 但是当我运行这个代码时,我得到: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), […]

尝试使用像pandas轴心pandas枢轴

我有一个像这样的pandas数据框架,我想使用pd.pivot_table来枢轴转动 import pandas df = pd.DataFrame({"Id":[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10], "Error":[0, 99, 0, 0, 0, 98, 0, 0, 0, 0, 33, 0, 23, 0, 0, 0, 83, 0]}) 我试图像这样旋转(在Excel中进行数据透视): 我试过这个: dfPivot = pd.pivot_table(df, index = "Id", columns = df.Error.unique(), values = "Error", […]

在读入xlsx文件后,不能取回列名

你好,我有xlsx文件,并通过使用pandas合并成一个数据框。 它的工作,而不是取回我在xlsx文件中的列名,我把数字作为列,而列标题成为一行:像这样: Output: 1 2 3 COLTITLE1 COLTITLE2 COLTITLE3 当他们应该是这样的: Output: COLTITLE1 COLTITLE2 COLTITLE3 列标题不是列标题,而是成为一排。 我怎样才能找回我在xlsx文件中的正确的列名。 为了清楚起见,所有列名在xlsx文件中都是相同的。 帮助将不胜感激inheritance人我的代码如下: # import modules from IPython.display import display import pandas as pd import numpy as np pd.set_option("display.max_rows", 999) pd.set_option('max_colwidth',100) %matplotlib inline # filenames file_names = ["data/OrderReport.xlsx", "data/OrderReport2.xlsx"] # read them in excels = [pd.ExcelFile(name) for name in file_names] […]

更改pandas中特定行的值

我需要在Python中的一些帮助。 我需要修改特定行中的值。 我有这样的事情 ID Status Customer Name 345 New Braskem SA 923 Closed Braskem 046 New Braskem SA 195 New Braskem SA 537 In Progress Braskem 237 On Hold Vale 355 Closed BIMBO 在这里,我需要将所有的客户名称“Braskem SA”更改为“Braskem”有人可以帮我一个这个好吗? 谢谢,我将很感激帮助,对不好的英语感到抱歉。

有没有办法读取所有行,直到使用Python Pandas遇到空行

我在Excel中有很多行,并且在空行之后行被填充了垃圾值。 有没有办法只使用Pythonpandas在Excel中的第一个空行之前的logging。

Python Pandas read_excelparsingPandas 0.18.1和Pandas> 0.19之间的MultiIndex数据框的不同行为

我完全困惑。 可能我想念pandas API的更新。 所以我有这个excel文件 在Pandas 0.18.1我在阅读和parsing文件时没有遇到任何问题。 我用下面的代码, import pandas as pd fname = 'SAMPLE_EXCEL_CAUSING_ERROR_IN_PANDAS_0_19_UP.xlsx' pd.read_excel(fname, 'Sheet1', header=[0,1], index=[0,1]) 它返回了我想要的东西。 最近,我更新了我的软件包,现在我的pandas version 0.20.1 。 但是,当我试图用相同的Excel文件执行相同的代码时,它返回一个错误。 这里是错误消息: ValueError: Length of new names must be 1, got 2 。 任何线索我在哪里错过了read_excel的新API? 我完全困惑。 是否有任何解决方法来读取MultiIndex列的excel文件? 我的真实数据有三级索引而不是二级索引。 非常感谢您的任何build议。 PS我不能降级到0.18.1因为我的用户使用0.20.1 UPDATE 奇怪的是,如果我将header设置为header=[1,2]那么它不会抛出任何错误消息。 但是,我的索引得到了错误的级别。 仍然试图解决这个问题的解决方法。

在Pandas和Excel中部分重复的条件格式

我有以下csv数据名为reviews.csv : Movie,Reviewer,Sentence,Tag,Sentiment,Text, Jaws,John,s1,Plot,Positive,The plot was great, Jaws,Mary,s1,Plot,Positive,The plot was great, Jaws,John,s2,Acting,Positive,The acting was OK, Jaws,Mary,s2,Acting,Neutral,The acting was OK, Jaws,John,s3,Scene,Positive,The visuals blew me away, Jaws,Mary,s3,Effects,Positive,The visuals blew me away, Vertigo,John,s1,Scene,Negative,The scenes were terrible, Vertigo,Mary,s1,Acting,Negative,The scenes were terrible, Vertigo,John,s2,Plot,Negative,The actors couldn't make the story believable, Vertigo,Mary,s2,Acting,Positive,The actors couldn't make the story believable, Vertigo,John,s3,Effects,Negative,The effects were awful, […]