投稿時間:2023-02-05 02:09:04 RSSフィード2023-02-05 02:00 分まとめ(9件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita pythonの-mオプションの動作を調べる https://qiita.com/Ryku/items/d9cebcb9e0a9e36281c6 pythonmmym 2023-02-05 01:18:33
python Pythonタグが付けられた新着投稿 - Qiita 【Python】pythonでwifi接続をしてみた。【pywifi】 https://qiita.com/shinfx/items/f7250730c0d8dabb5962 pywifi 2023-02-05 01:10:24
js JavaScriptタグが付けられた新着投稿 - Qiita 【Julia】Electron.jlを使ってカウンターアプリを作る https://qiita.com/MandoNarin/items/188a14565754612e31a0 electronjl 2023-02-05 01:58:02
海外TECH MakeUseOf How to Force Games Into Windowed Mode on Windows 10 & 11 https://www.makeuseof.com/windows-10-11-windowed-mode-games/ windows 2023-02-04 16:15:16
海外TECH DEV Community About "Await is only valid in Async functions" error in JavaScript https://dev.to/lavary/about-await-is-only-valid-in-async-functions-error-in-javascript-bmd About quot Await is only valid in Async functions quot error in JavaScriptUpdate This post was originally published on my blog decodingweb dev where you can read the latest version for a user experience rezaAwait is only valid in Async functions This syntax error occurs when you use an await expression outside an async execution context like an async function or top level body of an ES module top level await Here s what it looks like How to solve “await is only valid in async functions error Await expressions are used in two ways Using await expressions in async functionstop level awaitUsing await expressions in async functions If you re using an await expression in a function adding the async keyword to the function declaration resolves the issue Wrongfunction getBooks let books await fetch some url api v books Correctasync function getBooks let books await fetch some url api v books Just beware that once you make a function async it ll always return a promise So if you re using the respective function in other places remember to update your code accordingly You can also make callback functions async setTimeout async gt const items await getItems Top level await If your await statement isn t in a function you can wrap your code in an async IIFE Immediately Invoked Function Expression async gt let books await fetch some url api v books Any code here will be executed after the books variable has the value Await can be used on its own in ES modules too If you re using Node js you must set Node s module system to ES module system first Top level await isn t supported by the Node js default module system CommonJS To do that add type module to your package json file If you don t have a package json file yet run the following terminal command from your project directory npm initThen add type module to your module s configuration name test version description main app js type module scripts test echo Error no test specified amp amp exit author license ISC If your module is supposed to be loaded in a browser add type module to the lt script gt tag and you re good to go lt script type module src app js gt lt script gt If you re curious how async await works please read on Understanding async functions in JavaScriptAsync functions are easy to spot as they have the async keyword in their declaration async function myFunction await can be used here An async function always returns its value wrapped in a Promise if the returned value isn t already a promise You can access the returned value once it s resolved if not rejected Let s see an example async function asyncTest return let asyncFunctionValue asyncTest console log asyncFunctionValue output Promise Get the value when it s resolvedasyncFunctionValue then value gt console log value output So basically the async keyword implicitly wraps the returned value in a promise if it s not already a promise The above code is equivalent to the following function asyncTest let returnValue someValue return new Promise resolve returnValue Now what s the await keyword The async await duo enable you to write asynchronous code more cleanly by avoiding promise chains a cascade of then methods promiseObj then value gt some code here then value gt some code here then value gt some code here then value gt some code here The await keyword makes JavaScript look synchronous even though it never blocks the main thread The purpose of using await inside an async function is to write cleaner asynchronous code in promise based APIs like the Fetch API The rule is await expressions must be used inside async functions Otherwise you ll get the syntax error await is only valid in async functions and the top level bodies of modules Let s make it clear with an example Using the fetch API in the old fashioned way is like this fetch some url api v movies then response gt response json then data gt console log data But with async await you won t need then callbacks let response async gt let movies await fetch some url api v movies The code following await is treated as if they are in a then callback response await movies json So when JavaScript encounters an await expression in your async function it pauses the execution of the code following await and gets back to the caller that invoked the async function The code following await is pushed to a microtask queue to be executed once the promise being awaited is resolved The following code is a simplified and imaginary chatbot that starts a chat session with a user We have a function named say which returns messages after a delay to mimic human typing function say text delay return new Promise resolve gt setTimeout gt resolve text delay async function startConversation console log Hi console log await say my name is RB console log await say How can I help you startConversation console log Please input your email However the function doesn t return the messages in the order we expect Hi Please input your email my name is RB How can I help you The reason is once JavaScript gets to the first await it pauses the execution of what s left in the function and returns to the caller startConveration The main thread that is now freed prints the Please input your email message And once the promises are resolved the function s remaining lines are executed as if they were inside a callback function It s just the good old then callback functionality but more cleanly Additionally the async await duo lets us use try catch with promised based APIs Something you couldn t simply do with then callbacks let items try items await getItemsFromApi catch error Handle the error here A quick note on performanceSince the code after the await is to be paused execution you gotta make sure it s only followed by the code that depends on it Otherwise some operations will have to wait for no reason Imagine we need to get the best deals from Amazon and Etsy and merge the results into an array to be listed on a web page The following approach isn t optimized function getAmazonDeals get Amazon deals function getEtsyDeals get Etsy deals Using an IEEF function here async gt const amazonDeals await getAmazonDeals const etsyDeals await getEtsyDeals const allDeals amazonDeals etsyDeals populateDealsList allDeals In the above example the lines following the first await are paused until the data is fetched from Amazon This means the second request getEtsyDeals has to wait without being dependent on the return value of getAmazonDeals So if each request takes one second fetching deals from Amazon and Etsy would take two seconds in total But what if we initiated both requests concurrently and use await afterward Let s see how function getAmazonDeals get Amazon deals function getEtsyDeals get Etsy deals Using an IEEF function here async gt We re not using await here to initiate the requests immediately const amazonDeals getAmazonDeals const etsyDeals getEtsyDeals Since the result of both requests are still promises we use await when we want to combine them into one array The leads aren t populated until we have deals from both sources const allDeals await amazonDeals await etsyDeals populateDealsList allDeals Since both requests start immediately we have both responses in one second I hope you found this quick guide helpful Thanks for reading 2023-02-04 16:31:22
海外TECH DEV Community About "AttributeError module ‘DateTime’ has no attribute ‘strptime’" in Python https://dev.to/lavary/about-attributeerror-module-datetime-has-no-attribute-strptime-in-python-1k53 About quot AttributeError module DateTime has no attribute strptime quot in PythonUpdate This post was originally published on my blog decodingweb dev where you can read the latest version for a user experience rezaThe error “AttributeError module DateTime has no attribute strptime occurs when you call the strptime method on Python s datetime module rather than the datetime class inside it Here s what it looks like Traceback most recent call last File line in AttributeError module datetime has no attribute strptime If you get the above error your code probably looks similar to this import datetimedate string Dcember datetime object datetime strptime date string d B Y The reason is strptime method isn t a function defined inside the datetime module It s a method implemented by a class named datetime that happens to be inside the datetime module If you re wondering what a module is in Python here s a quick refresher Python lets you reuse functions classes etc by defining them in a file you can import into any script or module This py file is known as a Python module The datetime module contains classes for manipulating dates and times The datetime module contains a class definition of the same name datetime which implements the strptime method I know It s like there was a city in Canada named Canada Imagine sending a postcard there How to fix AttributeError module DateTime has no attribute strptime You have two options to fix this attribute error Call the method on the class datetimeimport the class datetime directlyCall the method on the class datetime One way to fix the error is to call the strptime method on the datetime datetime class This way you won t have to change your import statement import datetimedate string December datetime object datetime datetime strptime date string d B Y print datetime object The expression datetime datetime refers to the datetime class in the datetime module Here s the output Import the datetime class directly If you prefer not to touch your code you can edit your import statement instead from datetime import datetimedate string December datetime object datetime strptime date string d B Y print datetime object print type datetime object In the above code we explicitly imported the datetime class from the datetime module As a result any datetime instance points to the datetime class By the way always avoid naming a variable datetime because it ll override the reference to the datetime class And you ll get a similar attribute error if you call the strptime method Alright I think that does it I hope you found this quick guide helpful Thanks for reading ️You might like AttributeError str object has no attribute decode Fixed How back end web frameworks work Your master sword a programming language 2023-02-04 16:04:56
海外TECH DEV Community Completing missing combinations of categories in our data with pandas.MultiIndex! https://dev.to/chrisgreening/completing-missing-combinations-of-categories-in-our-data-with-pandasmultiindex-26jn Completing missing combinations of categories in our data with pandas MultiIndex The pandas MultiIndex is a powerful tool for handling multi level indexing in pandas DataFrames giving us increased flexibility for manipulating preparing and analyzing complex datasetsfrom pandas import MultiIndexLet s investigate how we can leverage MultiIndex to complete missing combinations of categories in our datasets with an incredibly elegant solution Table of ContentsUnderstanding missing combinations of categoriesCreating a MultiIndex with all possible combinations of categoriesReindexing our DataFrame to align with the MultiIndexConclusionAdditional resources Chris Greening Software Developer Hey My name s Chris Greening and I m a software developer from the New York metro area with a diverse range of engineering experience beam me a message and let s build something great christophergreening com Understanding missing combinations of categories When it comes to data preparation a common scenario we encounter is categorical data that spans across multiple levels of our dataset While working with this data it s important to understand and identify where our categories might contain missing combinationsA good example of this could be sales data that spans several geographic regions and product categories A missing combination might indicate that a particular product is not sold in a certain region OR that the data itself for that region product combination is missing Let s take this a step further and look at a simple dataset of spam and eggs sales in New York Texas and California can you tell which combinations of region and product are missing sales data region product sales New York spam New York eggs Texas eggs lt California spam lt In this case Texas is missing a row for spam sales and California is missing a row for eggs Some important questions to consider Were there zero sales so those rows were ommitted Are those products respectively not offered in Texas or California How will these missing combinations affect our analyses And instead of just leaving these combinations out it might be imperative to complete the missing categories and fill the associated values with zero or NA to give us a more complete picture of our dataset region product sales New York spam New York eggs Texas spam lt D Texas eggs California spam California eggs lt D What is MultiIndex As mentioned in the introduction MultiIndex is a powerful tool for managing DataFrame s that contain nested layers categories and or segmentationsIn our sales data example from the prior section we have multiple indices that categorize our sales data by regionproductBy leveraging MultiIndex we re able to encode this hierarchy into a DataFrame and gain access to an elegant toolkit for manipulating preparing and analyzing the different levels of our data Creating a MultiIndex with all possible combinations of categories Let s take our spam and eggs raw sales data from earlier now and store it in a DataFrame let s call it sales df import pandas as pdsales df pd DataFrame region New York New York Texas California product spam eggs eggs spam sales To create a MultiIndex that contains every possible combination of the unique values in region and product we can leverage the pd MultiIndex from product method by passing as arguments a list of lists containing every unique region and every unique product in our dataset and a list of strings containing the names of our columnsunique categories sales df region unique sales df product unique names region product multiindex pd MultiIndex from product unique categories names names gt gt gt print multiindex MultiIndex New York spam New York eggs Texas spam lt wow Texas eggs California spam California eggs lt great names region product Check it out By taking the cross product of our unique categories MultiIndex went ahead and created every possible combination of region and product for us Thanks MultiIndex you re the best Reindexing our DataFrame to align with the MultiIndex And for the grand finale We will reindex our DataFrame to align with our MultiIndex completing missing combinations and filling them with zero in the process To do this we will set our DataFrame s index on columns region and product using our names list from the previous sectionreindex our DataFrame using our multiindex and filling missing values with zeroand reset the index to remove the encoded hierarchysales df sales df set index names reindex multiindex fill value reset index gt gt gt print sales df region product sales New York spam New York eggs Texas spam lt yay Texas eggs California spam California eggs lt fantastic Conclusion And just like that we ve learned how we can use pandas MultiIndex to complete missing combinations with an incredibly elegant solutionWhile our product region example was trivial this will scale to an arbitrary amount of categorizations including time series i e dates weeks and months So get out there and go complete those missing combinations I believe in you If you want to take this a step further and practice with sample code and data I ve pulled together a full working example for you to explore on GitHub Thanks so much for reading and if you liked my content be sure to check out some of my other work or connect with me on social media or my personal website Chris Greening Software Developer Hey My name s Chris Greening and I m a software developer from the New York metro area with a diverse range of engineering experience beam me a message and let s build something great christophergreening com Cheers Leveraging the pipe method to write beautiful and concise data transformations in pandas Chris Greening・Jan ・ min read python datascience tutorial codequality Connecting to a relational database using SQLAlchemy and Python Chris Greening・Apr ・ min read python beginners tutorial database Additional resources minutes to pandasHow to Use MultiIndex in Pandas to Level Up Your Analysis by Byron DolonYouTube How do I use the MultiIndex in pandas 2023-02-04 16:00:29
海外TECH Engadget NVIDIA rolls out update for Discord performance bug https://www.engadget.com/nvidia-rolls-out-update-for-rtx-30-series-discord-performance-bug-165228788.html?src=rss NVIDIA rolls out update for Discord performance bugNVIDIA has begun rolling out a fix for a bug that had caused some of its GPUs to perform worse while people had Discord open In a tweet spotted by The Verge the company said Windows will now automatically download an app profile update the next time users log into their PC The update resolves an issue that prevented some NVIDIA GPUs including RTX series models like the and Ti from pushing their memory as fast as possible when Discord was open in the background In some instances NVIDIA users reported their video cards being throttled by as much as Mhz translating to a modest performance decrease in most games GeForce users can now download an app profile update for Discord This resolves a recent issue where some GeForce GPUs memory clocks did not reach full speed w Discord running in the background The update automatically downloads to your PC the next time you log into Windows pic twitter com nwugWQFFーNVIDIA Customer Care nvidiacc February Reddit and Linus Tech Tips forum users were among the first to spot and document the issue The bug was introduced in a recent Discord update that added AV codec support With the new codec RTX series users can stream their gameplay at up to K and frames per second over Discord Nitro The bug did not appear to affect RTX series cards That said NVIDIA quickly acknowledged the issue and offered a temporary workaround nbsp 2023-02-04 16:52:28
ニュース BBC News - Home Six Nations 2023: Wales 10-34 Ireland - Warren Gatland's return spoiled by clinical visitors https://www.bbc.co.uk/sport/rugby-union/64519964?at_medium=RSS&at_campaign=KARANGA Six Nations Wales Ireland Warren Gatland x s return spoiled by clinical visitorsWarren Gatland s return is spoiled by Ireland as the world s number one side humble Wales in the opening Six Nations match in Cardiff 2023-02-04 16:11:04

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)