I am reading in a CSV file in the following format:
N,X,Y,Z
Eventually, I want to:
plot(N,X,B,Y,N,Z)
First, I have to read the data in, which I have:
reshape(csv2cell('file.csv',',',1,0),DIMx,DIMy)
I know that:
N = [*,1]
X = [*,2]
Y = [*,3]
Z = [*,4]
How do I take the slices and put them into their own separate array, so that I can plot?
Related
I have to filter the data, therefore I need to create new CSV file based on the filters.
I am having a trouble doing it, cause the new file does not change after I run the code
Below is my code. Where I have two csv file. Stage_3_try.csv file is the one I am trying to add new data. I used enumerate to get the index value of the specific value I searched in previous csv file.
# Projec
import csv
from csv import writer
A = np.array([ 316143.8829, 6188926.04])
B = np.array([ 314288.7418, 6190277.519])
for i in range(0,len(east_3)):
P = []
P.append(east_3[i])
P.append( north_3[i])
P = np.asarray(P)
projected = point_on_line(P) #a code to do the projection
x_values = [A[0], B[0]]
y_values = [A[1], B[1]]
plt.plot(x_values, y_values, 'b-')
if projected[0]>315745.75 and projected[1]>6188289:
with open('Stage_3_try.csv', 'a') as f_out:
writer = csv.writer(f_out)
for num, row in enumerate(stage_3['UTM North NAD83']):
if row == P[1]:
writer.writerow(stage_3.loc[[num][0]])
print(type(stage_3.loc[[num][0]]))
plt.plot(projected[0], projected[1], 'rx')
f_out.close()
else:
pass
PS: I updated the code, since the previous one worked, but when I added it to the loop, it stopped working
I have made a code of creating a folder that shall contain the output of the same code in a csv file. But when I wish to make amendments to the code so as to modify the output obtained in the csv file, I do not wish to run into FileExistsError. Is there any way I can do that? Sorry if the query is a foolish one, as I am just beginning to learn Python. Here's my code:
path = Path('file\location\DummyFolder')
path.mkdir(parents=True)
fpath = (path / 'example').with_suffix('.csv')
colours = ['red','blue', 'green', 'yellow']
colour_count = 0
with fpath.open(mode='w', newline='') as csvfile:
fieldnames = ['number', 'colour']
thewriter = csv.DictWriter(csvfile, fieldnames=fieldnames)
thewriter.writeheader()
for colour in colours:
colour_count+=1
thewriter.writerow({'number':colour_count, 'colour':colour})
In one of my folders (say Folder01) there are files like "IGN_A.txt", "IGN_B.txt", "IGN_C.txt".........
In another folder (say Folder02) there are files like "sim_IGN_A_M01.txt", "sim_IGN_A_M02.txt", "sim_IGN_A_M03.txt" for the corresponding file "IGN_A.txt" in Folder01.
Similarly, "sim_IGN_B_M01.txt", "sim_IGN_B_M02.txt", "sim_IGN_B_M03.txt" for corresponding file "IGN_B.txt" in Folder01.
How can I get the corresponding files from those Folders.
For example, I want to get "IGN_A.txt" along with "sim_IGN_A_M01.txt", "sim_IGN_A_M02.txt", "sim_IGN_A_M03.txt".
Here. I added my code which can only get "IGN_A.txt" along with "sim_IGN_A.txt".
Folder01 = 'Home/A1';
Folder02 = 'Home/A2';
%Going Throuh all the Folder01 files
Allfiles_Folder01 = dir(fullfile(Folder01, '*IGN*.txt'));
for k = 1:length(Allfiles_Folder01)
fullFileName = fullfile(Folder01, Allfiles_Folder01(k).name);
READ_Folder01=dlmread(fullFileName,'',2,0);
fullFileName_Sim = fullfile(Folder02, strcat('sim_',Allfiles_Folder01(k).name))
READ_Folder02=dlmread(fullFileName_Sim,'',1,0);
end
If the naming convention is consistent as provided by you, this would be my suggestion:
% Get all filenames from Folder01 in cell array.
Allfiles_Folder01 = dir(fullfile(Folder01, '*IGN*.txt'));
Allfiles_Folder01 = {Allfiles_Folder01.name}
% Iterate all filenames from Folder01.
for k = 1:numel(Allfiles_Folder01)
% Cut file extension from current filename.
filename = Allfiles_Folder01{k};
filename = filename(1:end-4);
% Get all filenames from Folder02 with specific search string in cell array.
Allfiles_Folder02 = dir(fullfile(Folder02, strcat('*', filename, '*.txt')));
Allfiles_Folder02 = {Allfiles_Folder02.name}
% Do stuff with filenames from Folder02 corresponding to filename from Folder01.
% ...
% ...
end
I have a for loop iterating over a folder of one column csv's using glob, it makes some adjustments and then appends the results to a list and saves to a new csv, it resembles:
data= []
infiles = glob.glob("*.csv")
for file in infiles:
df = pd.io.parsers.read_csv(file)
(assorted adjustments)
data.append(df)
fullpanel = pd.concat(panel)
fullpanel.to_csv('data.csv')
The problem is that makes one long column, I need each column (of differing lengths) added next to each other.
I think you can add parameter axis=1 to concat for columns added next to each other. Also you can change pd.io.parsers.read_csv to pd.read_csv and panel to data in concat.
data= []
infiles = glob.glob("*.csv")
for file in infiles:
df = pd.read_csv(file)
(assorted adjustments)
data.append(df)
fullpanel = pd.concat(data, axis=1)
fullpanel.to_csv('data.csv')
I'm writing a trivia game app in C# that writes data to a binary file, then reads the data from the file into six labels. The six labels are as follows:
lblQuestion // This is where the question text goes.
lblPoints // This is where the question points goes.
lblAnswerA // This is where multiple choice answer A goes.
lblAnswerB // This is where multiple choice answer B goes.
lblAnswerC // This is where multiple choice answer C goes.
lblAnswerD // This is where multiple choice answer D goes.
Here is the code for writing to the binary file:
{
bw.Write(Question);
bw.Write(Points);
bw.Write(AnswerA);
bw.Write(AnswerB);
bw.Write(AnswerC);
bw.Write(AnswerD);
}
Now for the code to read data from the file into the corresponding labels:
{
FileStream fs = File.OpenRead(ofd.FileName);
BinaryReader br = new BinaryReader(fs);
lblQuestion.Text = br.ReadString();
lblPoints.Text = br.ReadInt32() + " points";
lblAnswerA.Text = br.ReadString();
lblAnswerB.Text = br.ReadString();
lblAnswerC.Text = br.ReadString();
lblAnswerD.Text = br.ReadString();
}
The Question string reads correctly into lblQuestion.
The Points value reads correctly into lblPoints.
AnswerA, AnswerB, and AnswerC DO NOT read into lblAnswerA, lblAnswerB and lblAnswerC respectively.
lblAnswerD, however, gets the string meant for lblAnswerA.
Looking at the code for reading data into the labels, is there something missing, some sort of incremental value that needs to be inserted into the code in order to get the strings to the correct labels?