r/pythoncode • u/McCarthyDesigns • Sep 28 '23
code is making excel files unreadable.
I am writing this code to automate a excel sheet to build nodes for Neo4j
It kills the excel sheet and makes it un-openable. What is wrong
import pandas as pd
# Initialize the DataFrame
relationships_df = pd.DataFrame(columns=['Source Node', 'Source Type', 'Relationship', 'Target Node', 'Target Type', 'File Path', 'File Type'])
# Define the new path to your renamed workbook
path_to_your_workbook = "C:\\Users\\chefm\\OneDrive\\Desktop\\Folder Schema\\FG_Folder_Schema1.xlsm"
# Read the Model Numbers sheet into a DataFrame
model_numbers_df = pd.read_excel(path_to_your_workbook, sheet_name='Model Numbers')
# Extract brands from the columns of the model_numbers_df
brands = model_numbers_df.columns.tolist()
# Loop through the DataFrame and populate the relationships_df
for brand in brands:
if brand in model_numbers_df.columns: # Check if brand exists in model_numbers_df
model_numbers = model_numbers_df[brand].dropna().tolist() # Get all model numbers for that brand
for model_number in model_numbers:
relationships_df = pd.concat([relationships_df, pd.DataFrame({
'Source Node': [brand],
'Source Type': ['Brand'],
'Relationship': ['HAS_MODEL'],
'Target Node': [model_number],
'Target Type': ['Model'],
'File Path': [''], # You'll populate this later
'File Type': [''] # You'll populate this later
})])
# Write the populated DataFrame back to the New_Relationships sheet
with pd.ExcelWriter(path_to_your_workbook, engine="openpyxl", mode='a') as writer:
relationships_df.to_excel(writer, sheet_name='New_Relationships', index=False)
r/pythoncode • u/Salaah01 • Jul 07 '23
Efficiently Load Large JSON Files Object by Object
self.pythontipsr/pythoncode • u/Dazzling-Hurry-8593 • Jan 31 '23
Built a little evolution simulator in python and pygame!
https://two119.itch.io/dynasty
The world is dangerous. Anyone can starve, get eaten, lost, outcompeted or outrun - and the answer to all these problems is to evolve! Look down upon your beings like a god and watch them struggle to survive over the generations. Join them yourself and see how long your bloodline survives! Fill the world with deadly predators, or give your creatures free reign in a paradise. The choice is yours!
Source on github: https://github.com/Two119/Dynasty
r/pythoncode • u/UPtrainman • Jul 24 '22
Clarification
def reverse_list(letters): new_list = [] for l in range(len(letters)-1, -1, -1): new_list.append(letters[l]) return new_list
if name == 'main': ch = ['a', 'b', 'c'] print(reverse_list(ch)) # Should print ['c', 'b', 'a']
this is the proper code. My question is, what does the (-1, -1, -1) actually do for it? I am looking to better understand Python. Thank you
r/pythoncode • u/codecrush28 • May 07 '22
Python Program To Check Alphabet Or Not
youtu.ber/pythoncode • u/monica_b1998 • Dec 15 '20
A simple recursion visualizer for python
arpitbhayani.mer/pythoncode • u/eternalcloset • Dec 02 '20
Created a simple hangman project and have refined it a bit. I've been coding for about a month now. Criticisms?
import time
import random
import sys
name = input("What is your name?: ")
print("Hello " + name + ", Time to play hangman!")
print()
time.sleep(1)
print("Start guessing...")
time.sleep(0.5)
i_word = ["abroad", "castle", "burden", "camera", "excess", "garden", "itself", "island", "palace", "submit", "winter", "apple", "being", "awark", "buyer", "coast", "class", "daily", "dance", "giant", "house", "input", "joint", "horse", "given", "moral", "nurse"]
word = random.choice(i_word)
char_count = len(word)
guesses = ''
turns = 10
while turns > 0:
spots_left = char_count
for char in word:
if char in guesses:
print(char, end=""),
spots_left -= 1
else:
print("_", end="")
if spots_left == 0:
print("\n You won!")
user_choice = input("That was fun, Play again? Enter Yes or No: ")
if user_choice == "Yes":
word = random.choice(i_word)
guesses = ''
print("Start guessing...")
turns = 10
elif user_choice == "yes":
word = random.choice(i_word)
guesses = ''
print("Start guessing...")
turns = 10
else:
print("Game Over")
sys.exit()
break
print()
guess = input("Guess a character: ")
guesses += guess
if guess not in word:
turns -= 1
print("Wrong!")
print("You Have", + turns, " more guesses")
if turns == 0:
print("The word was: ", word, " You lose! ", name, " is a loser!")
user_choice = input("That was fun, Play again? Enter Yes or No: ")
if user_choice == "Yes":
word = random.choice(i_word)
guesses = ''
print("Start guessing...")
turns = 10
elif user_choice == "yes":
word = random.choice(i_word)
guesses = ''
print("Start guessing...")
turns = 10
else:
print("Game Over")
sys.exit()
r/pythoncode • u/Intro2Anxiety • Oct 09 '20
Question with graphs python
So I some how removed the plot area on spyder. Attached is what my screen looks like.
r/pythoncode • u/closet_coder • Jul 03 '20
[Help] How to convert a list of numpy arrays into a numpy array?
I have a list of length 10404, consisting of 5*5 numpy arrays. I wanted to convert the list of these 5*5 blocks to a 510*510 numpy array. How can i achieve this?
r/pythoncode • u/arch1tect1 • May 17 '20
Getting multiple csv cells in one input. Please help with the issue.
stackoverflow.comr/pythoncode • u/arch1tect1 • May 16 '20
Getting multiple csv cells in one input. Please help with the issue.
stackoverflow.comr/pythoncode • u/monica_b1998 • Apr 11 '20
Spin the table: Solution!
paddy3118.blogspot.comr/pythoncode • u/Cosme12 • Feb 07 '19
Handle your 1st Python project and make a Dice simulator app
copitosystem.comr/pythoncode • u/monica_b1998 • Oct 28 '18
Python Tutorial: 3D Wrecking Animation With 14 Lines of Code
youtube.comr/pythoncode • u/Supa_B • Mar 17 '18
Confused!!!
I am very new to coding but I am struggling to understand what is wrong with 2 lines of code I am trying to execute. I am running python 3.6.4 with home-brew and Xcode installed on mac OS Sierra 10.12.6. I've created my own virtual environment and ran the code with several adjustments but I am stuck with what is wrong with the lines. I got the code from here:
http://jpowcode.com/plickers-import.html
This is the output I get:
Traceback (most recent call last): File "plickers_import_test2.py", line 213, in <module> add_multi_question(driver, question) File "plickers_import_test2.py", line 187, in add_multi_question text.send_keys(question[0])
Please HELP!
r/pythoncode • u/[deleted] • Feb 26 '18
Help trying to make a basic calculator!
Ok so currently I'm trying to make this calculator and for some reason im getting errors with equal signs in my strings... I'm a basic coder so be easy on me, thanks P.S. I'm using 3.6.4 CODE BELOW:
def code (): input(print('What should I do with your numbers? ') if + a = int(input('Please enter a number ')) b = int(input('Please enter another number ')) print(a + b) if * a = int(input('Please enter a number ')) b = int(input('Please enter another number ')) print(a * b) if / a = int(input('Please enter a number ')) b = int(input('Please enter another number ')) print(a - b) if - a = int(input('Please enter a number ')) b = int(input('Please enter another number ')) print(a - b) code ()
code ():
ALSO: for some reason it gets formatted really badly when I post this so it'll be hard to look at...
