[Solved] How do I print lines separately from a txt file in Python 3?

import time file = open(“abc.txt”,”r”) #<– Opening file as read mode data = file.read() #<– Reading data file.close() #<– Closing file data = data.split(“\n”) #<– Splitting by new lines for i in data: #<– Looping through splitted data print(i) #<– Printing line time.sleep(3) #<– Waiting for 3 seconds 1 solved How do I print lines … Read more

[Solved] Pivoting a One-Hot-Encode Dataframe

Maybe I’m missing something but doesn’t this work for you? agg = df.groupby(‘number_of_genres’).agg(‘sum’).T agg[‘totals’] = agg.sum(axis=1) Edit: Solution via pivot_table agg = df.pivot_table(columns=”number_of_genres”, aggfunc=”sum”) agg[‘total’] = agg.sum(axis=1) 2 solved Pivoting a One-Hot-Encode Dataframe

[Solved] Uploading a file in a embed discord.py (not a image)

if you want to put the file in an embed, that is not possible, discord themselves haven’t allowed for that. You can send a file and a message at the same time. Here’s how: @client.command() async def name(ctx): embed = discord.Embed(colour=0x00000) embed.title = f”your title” embed.description = f”your desc” await ctx.send(embed=embed) await ctx.file.send(“filename.txt”) 0 solved … Read more

[Solved] How to change this list tuple into list only in Python? [closed]

test = [[(u’hello’,), (u’hello’,)], [(u’hello’,)]] for i, part_i in enumerate(test): for j, part_j in enumerate(part_i): test[i][j] = str(part_j[0]) Or, if you prefer the one-line version: test = [[(u’hello’,), (u’hello’,)], [(u’hello’,)]] result = [[str(j[0]) for j in i] for i in test] solved How to change this list tuple into list only in Python? [closed]

[Solved] Search through JSON query from Valve API in Python

If you are looking for a way to search through the stats list then try this: import requests import json def findstat(data, stat_name): for stat in data[‘playerstats’][‘stats’]: if stat[‘name’] == stat_name: return stat[‘value’] url = “http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=FE3C600EB76959F47F80C707467108F2&steamid=76561198185148697” data = requests.get(url).text data = json.loads(data) total_kills = findstat(data, ‘total_kills’) # change ‘total_kills’ to your desired stat name print(total_kills) … Read more

[Solved] How to find the nth digit in a list in python

Lists work in an index form. So index[0] of a list is the first item. So to find the nth item in a list, your code would look something like this. list = [a, b, c, d, e, f, g] chosen_number = input(“Which number would you like from 1-7?”) print(“The item {} places into the … Read more

[Solved] How to add a label to all words in a file? [closed]

If I understand the correct output format word-O, you can try something like this: words = open(‘filename’).read().split() labeled_words = [word+”-O” for word in words] # And now user your output format, each word a line, separate by tabs, whatever. # For example new lines with open(‘outputfile’,’w’) as output: output.write(“\n”.join(labeled_words)) 3 solved How to add a … Read more