This is so perfect- a real-world example and straight to the point- and still relevant three years later- cheers Adam-
@kakairecharles34742 жыл бұрын
Million thanks. All is very simplified in an intersting way.
@sharmaaks7293 жыл бұрын
Exactly what I was searching for... thanks a lot
@hungtruong5523 Жыл бұрын
Oh god, thank you, my savior
@jaggyjut3 жыл бұрын
Great explanation. Would you be able to create a tutorial on reading values in a text file using splitlines, previous_lines nested in a for loop. Basically like to know how to take field & respective value from a text file and output them into a pandas dataframe.
@AMGaweda3 жыл бұрын
I'm not quite sure what you mean, but I HAVE had to create a blank DataFrame from scratch before. Start by creating a blank DataFrame with a list of field names. new_df = pd.DataFrame(columns=['fname', 'lname', 'email', 'password']) # for example Then, as you iterate through your text / data, create a blank dictionary and then add in the values to the dictionary entry = {"fname": "Adam", "lname": "Gaweda", "email": "abcdefg@email", "password": "bubbles"} Finally, append this entry to the DataFrame and then replace the old DataFrame with the newly appended version. new_df = new_df.append(entry, ignore_index=True) The ignore_index parameter says "Don't worry about where to add the entry, just put it at the bottom".
@Kig_Ama4 жыл бұрын
How can I read from file faster via multiprocessing using Python?
@willfenno20943 жыл бұрын
how would you find the maximum temperature from what you outputted at the end?
@AMGaweda3 жыл бұрын
In that case you'd want to create a "current_max" variable before the loop, it could be set to -1 or -10000 (mostly depends on your data). Then, as you traverse the lines in the file, you'd do a conditional statement to see if reading > current_max. If so, update current_max to be this new largest value.
@mouradhamdaoui13932 жыл бұрын
pls how can i replace a values with NAN
@cliosport13747 ай бұрын
👍👌👍
@НеъматовИсломбек3 жыл бұрын
thanks that was really helpful !!!
@ronnievincent78954 жыл бұрын
If i have a list with strings having 2 values and 1 value for example Adair, KY Jackson, AL Chicago,IL ALASKA how could i rewrite my data to a new file switching state and city and leaving out the uppercase state for example KY: Adair AL: Jackson IL:Chicago When I run what i got i get a 'list index out of range error' because of the uppercase State only having on value. This is the code I have so far. I've been searching for help for 2 days, so anything you got would be much appreciated. county_file = open("c:\\Python 3.8.3\\us-counties.2.txt", "r") lines = county_file.readlines() state_file = open("c:\\Python 3.8.3\\Ronnie.Vincent.County.Seats.manipulated.txt", "w") for aline in lines: values = aline.split() print(values[1],':', values[0]) state_file.close() county_file.close()
@AMGaweda4 жыл бұрын
In your line "print(values[1],':', values[0])", you are assuming there is a values[1]. You could check the length of values via "if len(values) == 2" before printing to know whether the line wa split into a list with multiple elements. If that conditional is false, say like with Alaska, you could handle it in with an 'else'.
@chandrakanthurs74703 жыл бұрын
What can we do if data in table form is not alligned , how can we extract that index
@AMGaweda3 жыл бұрын
If your data is separated by something like a comma (,) then your file is using what is known as a delimiter to separate values. You can handle this a few different ways: 1) The line.split function can include '"," inside it which will split on the commas [so, line.split(",") ]. 2) If you are using a CSV file, you can also use Python's csv library to process the file for you. You can see how this works in this video - kzbin.info/www/bejne/rHqwZKKfhJ2qatE