我有以下玩具代码:
import pandas as pd
df = pd.DataFrame()
df["foo"] = [1,2,3,4]
df2 = pd.DataFrame()
df2["bar"]=[4,5,6,7]
df = pd.concat([df,df2], ignore_index=True,axis=1)
print(list(df))
Run Code Online (Sandbox Code Playgroud)
输出:[0,1]
预期输出:( [foo,bar]顺序并不重要)
如果可以保证标题是唯一的,是否有任何方法可以连接两个数据帧而不会丢失原始列标题?
我想到迭代列然后将它们添加到其中一个DataFrame中,但有没有pandas函数或concat我不知道的参数?
谢谢!
我正在编写一个应用程序来捕获使用该CopyFromScreen方法的屏幕,并且还想保存我捕获的图像以通过我的本地网络发送.所以,我正在尝试将捕获的屏幕存储在一个位图上,并在两个线程上保存另一个位图,即先前捕获的屏幕.
然而,这是抛出一个InvalidOperationException,说对象目前在其他地方使用.System.Drawing.dll抛出异常.
我尝试过锁定,并使用单独的位图来保存和捕获屏幕.我如何阻止这种情况发生?相关代码:
Bitmap ScreenCapture(Rectangle rctBounds)
{
Bitmap resultImage = new Bitmap(rctBounds.Width, rctBounds.Height);
using (Graphics grImage = Graphics.FromImage(resultImage))
{
try
{
grImage.CopyFromScreen(rctBounds.Location, Point.Empty, rctBounds.Size);
}
catch (System.InvalidOperationException)
{
return null;
}
}
return resultImage;
}
void ImageEncode(Bitmap bmpSharedImage)
{
// other encoding tasks
pictureBox1.Image = bmpSharedImage;
try
{
Bitmap temp = (Bitmap)bmpSharedImage.Clone();
temp.Save("peace.jpeg");
}
catch (System.InvalidOperationException)
{
return;
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 30;
timer1.Start();
}
Bitmap newImage = null; …Run Code Online (Sandbox Code Playgroud)