delimited-text

import text to pandas with multiple delimiters

偶尔善良 提交于 2019-11-27 04:25:30
I have some data that looks like this: c stuff c more header c begin data 1 1:.5 1 2:6.5 1 3:5.3 I want to import it into a 3 column data frame, with columns e.g. a , b, c 1, 1, 0.5 etc I have been trying to read in the data as 2 columns split on ':', and then to split the first column on ' '. However I'm finding it irksome. Is there a better way to sort it out on import directly? currently: data1 = pd.read_csv(file_loc, skiprows = 3, delimiter = ':', names = ['AB', 'C']) data2 = pd.DataFrame(data1.AB.str.split(' ',1).tolist(), names = ['A','B']) However this is further complicated by the fact

c# datatable to csv

别等时光非礼了梦想. 提交于 2019-11-26 00:40:23
问题 Could somebody please tell me why the following code is not working. The data is saved into the csv file, however the data is not separated. It all exists within the first cell of each row. StringBuilder sb = new StringBuilder(); foreach (DataColumn col in dt.Columns) { sb.Append(col.ColumnName + \',\'); } sb.Remove(sb.Length - 1, 1); sb.Append(Environment.NewLine); foreach (DataRow row in dt.Rows) { for (int i = 0; i < dt.Columns.Count; i++) { sb.Append(row[i].ToString() + \",\"); } sb

c# datatable to csv

别来无恙 提交于 2019-11-25 18:42:03
Could somebody please tell me why the following code is not working. The data is saved into the csv file, however the data is not separated. It all exists within the first cell of each row. StringBuilder sb = new StringBuilder(); foreach (DataColumn col in dt.Columns) { sb.Append(col.ColumnName + ','); } sb.Remove(sb.Length - 1, 1); sb.Append(Environment.NewLine); foreach (DataRow row in dt.Rows) { for (int i = 0; i < dt.Columns.Count; i++) { sb.Append(row[i].ToString() + ","); } sb.Append(Environment.NewLine); } File.WriteAllText("test.csv", sb.ToString()); Thanks. The following shorter