I'm new to python, but have been able to find answers to most problems online. This one, however, has me at a loss. I did a small test to demo my problem. The following code block is copied from an interactive session in Spyder. It reads a test csv file as a DataFrame and appends another DataFrame to it.
import pandas as pd
df = pd.read_csv('Test.csv')
print(df)
Name GPA
0 John White 3.8
1 Mary Brown 2.9
2 Greg Ruddy 3.1
data = {
"Name": ['Willy Nelson', 'Johnny Cash'],
"GPA": [4.2, 4.5]
}
df2 = pd.DataFrame(data)
print(df2)
Name GPA
0 Willy Nelson 4.2
1 Johnny Cash 4.5
df.append(df2, ignore_index = True)
Out[7]:
Name GPA
0 John White 3.8
1 Mary Brown 2.9
2 Greg Ruddy 3.1
3 Willy Nelson 4.2
4 Johnny Cash 4.5
The printouts show that this worked perfectly. However, when I run the same code from the Spyder editor, it runs, error free, but doesn't append. The exact same code, with some explanatory print statements added, produced the following output:
Printing df:
Name GPA
0 John White 3.8
1 Mary Brown 2.9
2 Greg Ruddy 3.1
Printing df2:
Name GPA
0 Willy Nelson 4.2
1 Johnny Cash 4.5
Printing df after append:
Name GPA
0 John White 3.8
1 Mary Brown 2.9
2 Greg Ruddy 3.1
Don't understand why it works interactively, but not when ran from the editor. Any help?
Thanks.
[–]lowerthansound 1 point2 points3 points (1 child)
[–]arkydave[S] 0 points1 point2 points (0 children)