我试图遍历一个具有列= [myCol]的空值的数据帧.我可以很好地遍历数据帧,但是当我指定我只想看到空值时,我得到一个错误.
最终目标是我想强制一个值进入Null字段,这就是为什么我要迭代来识别哪个是第一个.
for index,row in df.iterrows():
if(row['myCol'].isnull()):
print('true')
AttributeError: 'str' object has no attribute 'isnull'
Run Code Online (Sandbox Code Playgroud)
我尝试指定column ='None',因为这是我在打印数据帧迭代时看到的值.仍然没有运气:
for index,row in df.iterrows():
if(row['myCol']=='None'):
print('true')
No returned rows
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢!
我收到“ ImportError:DLL加载失败:找不到指定的模块。” 导入模块seaborn时。
我尝试卸载seaborn和matplotlib,然后通过使用重新安装
pip install seaborn
Run Code Online (Sandbox Code Playgroud)
但没有运气。我仍然遇到相同的错误。
ImportError Traceback (most recent call last)
<ipython-input-5-085c0287ecb5> in <module>()
----> 1 import seaborn
C:\Users\johnsam\venv\lib\site-packages\seaborn\__init__.py in <module>()
4
5 # Import seaborn objects
----> 6 from .rcmod import *
7 from .utils import *
8 from .palettes import *
C:\Users\johnsam\venv\lib\site-packages\seaborn\rcmod.py in <module>()
6 import matplotlib as mpl
7
----> 8 from . import palettes, _orig_rc_params
9
10
C:\Users\johnsam\venv\lib\site-packages\seaborn\palettes.py in <module>()
10 from .external.six.moves import range
11
---> 12 from .utils import …Run Code Online (Sandbox Code Playgroud) 对于我的数据集,我想用数据帧中的第一列替换自动索引,并用数据帧的所有列名内联设置新的索引标题。
原始数据集:
import numpy as np
import pandas as pd
df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6]]),columns=['a','b','c'])
df
a b c
0 1 2 3
1 4 5 6
Run Code Online (Sandbox Code Playgroud)
将索引设置为第一列:
df.set_index('a',inplace=True)
df
b c
a
1 2 3
4 5 6
Run Code Online (Sandbox Code Playgroud)
但是,现在我仍然停留在如何使索引标题与列标题内联的问题上。以下是我正在寻找的输出:
a b c
1 2 3
4 5 6
Run Code Online (Sandbox Code Playgroud) 我正在从Powershell启动工作簿中的宏(以使过程自动化)。Powershell中的以下内容将打开excel工作簿并运行宏而不可视化该过程。
问题是,即使我没有看到宏在运行,从宏生成的excel新实例仍处于打开状态。
# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'C:\file\Book1.xlsm'
$workbook = $excel.Workbooks.Open($FilePath)
#access the Application object and run a macro
$app = $excel.Application
$app.Run("macro")
#close excel
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Start-Sleep 1
'Excel processes: {0}' -f @(Get-Process excel -ea 0).Count
Remove-Variable $excel
exit $LASTEXITCODE
Run Code Online (Sandbox Code Playgroud)
excel文件仍作为任务管理器中的一个进程出现,并占用了内存空间。
我如何让Powershell完全关闭通过宏打开的excel应用程序的实例?
任何帮助,不胜感激!
I am trying to add a vba_project to "Sheet1" of a workbook using python.
I am following XLSXWRITER documentation to get the bin of the VBA code from a different sheet which I would want to use in "Sheet1" of my new workbook.
I enter the below code in command prompt but I get the error: "'vba_extract.py' is not recognized as an internal or external command"
$ vba_extract.py Book1.xlsm
Extracted: vbaProject.bin
Run Code Online (Sandbox Code Playgroud)
Can someone give me a step by step on …
我想将数据帧转换为json,这是我目前拥有的代码:
my_frame = pd.DataFrame(
{'Age':[30, 31],
'Eye':['blue', 'brown'],
'Gender': ['male', 'female']})
my_frame = my_frame.to_json(orient='records')
my_frame
Run Code Online (Sandbox Code Playgroud)
结果:
'[{"Age":30,"Eye":"blue","Gender":"male"},{"Age":31,"Eye":"brown","Gender":"female"}]'
Run Code Online (Sandbox Code Playgroud)
我想键添加到JSON对象,并添加关键信息在一个从数据框转换的整个数据.
add_keys = {'id': 101,
'loc': 'NY',
}
add_keys['info'] = my_frame
add_keys
Run Code Online (Sandbox Code Playgroud)
结果:
{'id': 101,
'info': '[{"Age":30,"Eye":"blue","Gender":"male"},
{"Age":31,"Eye":"brown","Gender":"female"}]',
'loc': 'NY'}
Run Code Online (Sandbox Code Playgroud)
我想在info中打印两个记录中的每一个,但是当我运行这个迭代代码时,它会输出字符串的每个字符而不是整个记录.我相信这可能是我如何添加密钥的问题.
for item in add_keys['info']:
print(item)
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢!
我正在使用下面的自由文本来学习java的介绍,我无法理解代码段之间的区别:
http://math.hws.edu/eck/cs124/downloads/javanotes7-linked.pdf
例1
int x;
x = -1;
if (x < 0)
x = 1;
else
x = 2;
Run Code Online (Sandbox Code Playgroud)
例2
int x;
x = -1;
if (x < 0)
x = 1;
if (x >= 0)
x = 2;
Run Code Online (Sandbox Code Playgroud)
在例1中,x是1; 在示例2中,x是2.
在右边,如果-1不是>或=到0那么输出不应该是1?有人可以解释为什么输出会改为2吗?
python ×5
dataframe ×2
excel ×2
pandas ×2
vba ×2
excel-vba ×1
if-statement ×1
java ×1
json ×1
matplotlib ×1
null ×1
powershell ×1
seaborn ×1