csv

Read multiple csv files into separate pandas dataframes

梦想的初衷 提交于 2021-02-08 07:49:11
问题 I've seen a few answers on reading multiple csv files into separate Pandas dataframes, and am still running into trouble. I've read my csv files and file names into a dictionary: path = os.getcwd() file_names = ['file1', 'thisisanotherfile', 'file3'] df_dict = {x: pd.read_csv('{}/{}.csv'.format(path, x)) for x in file_names} Which seems to work: print(df_dict['file1']) However what I'm looking for is a Pandas dataframe called 'file1' where I can access the data. Is it possible to get this

Read multiple csv files into separate pandas dataframes

一世执手 提交于 2021-02-08 07:49:01
问题 I've seen a few answers on reading multiple csv files into separate Pandas dataframes, and am still running into trouble. I've read my csv files and file names into a dictionary: path = os.getcwd() file_names = ['file1', 'thisisanotherfile', 'file3'] df_dict = {x: pd.read_csv('{}/{}.csv'.format(path, x)) for x in file_names} Which seems to work: print(df_dict['file1']) However what I'm looking for is a Pandas dataframe called 'file1' where I can access the data. Is it possible to get this

Importing CSV data into HTML form

末鹿安然 提交于 2021-02-08 07:46:34
问题 I need to import data from csv file into form. I tried example from this topic: How to import CSV file into HTML form, and export HTML form to CSV file Unfortunately it does not work for me. The file is opening, but no data are put into form. My index.html file looks as follows: <html lang="en"> <head> <meta charset="utf-8"> <script type="text/javascript" language="JavaScript" src="script.js"></script> <script src="https://d3js.org/d3.v3.js"></script> </head> <body> <input id="upload" type=

Importing CSV data into HTML form

无人久伴 提交于 2021-02-08 07:46:31
问题 I need to import data from csv file into form. I tried example from this topic: How to import CSV file into HTML form, and export HTML form to CSV file Unfortunately it does not work for me. The file is opening, but no data are put into form. My index.html file looks as follows: <html lang="en"> <head> <meta charset="utf-8"> <script type="text/javascript" language="JavaScript" src="script.js"></script> <script src="https://d3js.org/d3.v3.js"></script> </head> <body> <input id="upload" type=

Import .csv files into SQL database using SQLite in Python

☆樱花仙子☆ 提交于 2021-02-08 07:32:59
问题 I have 2 .txt files, and I converted them into .csv files using https://convertio.co/csv-xlsx/. Now, I would like to import these two .csv files into two databases using SQLite in Python (UI is Jupyter Notebook). These two .csv files are labeled person.csv and person_votes.csv . So, I did it by following the code given here (Importing a CSV file into a sqlite3 database table using Python): import sqlite3, csv con = sqlite3.connect(":memory:") cur = con.cursor() cur.execute("CREATE TABLE

Error handling ñ in pandas

流过昼夜 提交于 2021-02-08 07:23:27
问题 I am writing a script that reads a csv file and uses the pandas library to create a pivot table. I keep receiving an error ('utf-8' codec can't decode byte 0xf1 in position 6: invalid continuation byte) that I have linked back to the use of 'ñ' in one of the names in the csv file. I have searched for hours trying to find a way to handle this. I have tried including the encoding type in my pandas.read_csv and have had no luck. Here is my code: df = pandas.read_csv( os.path.join(wd,'Birthday_%s

Error handling ñ in pandas

纵然是瞬间 提交于 2021-02-08 07:22:06
问题 I am writing a script that reads a csv file and uses the pandas library to create a pivot table. I keep receiving an error ('utf-8' codec can't decode byte 0xf1 in position 6: invalid continuation byte) that I have linked back to the use of 'ñ' in one of the names in the csv file. I have searched for hours trying to find a way to handle this. I have tried including the encoding type in my pandas.read_csv and have had no luck. Here is my code: df = pandas.read_csv( os.path.join(wd,'Birthday_%s

Using Pandas to calculate distance between coordinates from imported csv

耗尽温柔 提交于 2021-02-08 07:21:52
问题 I am trying to import a .csv that contains two columns of location data (lat/long), compute the distance between points, write the distance to a new column, loop the function to the next set of coordinates, and write the output data frame to a new .csv. I have the following code written and it import pandas as pd import numpy as np pd.read_csv("input.csv") def dist_from_coordinates(lat1, lon1, lat2, lon2): R = 6371 # Earth radius in km #conversion to radians d_lat = np.radians(lat2-lat1) d

Save as different file type

核能气质少年 提交于 2021-02-08 07:14:10
问题 I would like to make my macro able to save a xlsx file as csv exactly with the same name when running it. This is what I tried: ActiveWorkbook.saveas Filename:=ActiveWorkbook.Path & "\" & _ ActiveWorkbook.Name & ".csv", FileFormat:=xlCSV, CreateBackup:=False However, it saves the file as .xlsx.csv (i.e, a file called prices.xlsx is saves as prices.xlsx.csv) How could I save the file with a different file extension, without the .xlsx? 回答1: If you want to make it more failsafe, in case your

How can I place user input into a CSV file?

微笑、不失礼 提交于 2021-02-08 06:43:58
问题 There have been a bunch of permutations of my question but the closest answer: How do I write a Python dictionary to a csv file? unfortunately printed output on each row like so: matthew, green rachel, blue raymond, red where somedict = dict(raymond = "red", rachel = "blue", matthew = "green") and my problem requires output more like this: why, date, story "because", "sunday", "blah blah blah" I'm getting the dictionary from user input, and it's important that the output file places each new