Concatenate csv column to string and print specific valueIs there a built-in function to print all the current properties and values of an object?Convert array to CSV/TSV-formated string in PythonPython Print String To Text FileHow can I print literal curly-brace characters in python string and also use .format on it?Concatenate item in list to stringsSelecting and operating on columns in a .csvSelect rows from a DataFrame based on values in a column in pandasPython - Using Input From CSV File/Splitting a StringBuild string by selecting column in csvHow to convert the column to numeric in python for sorting

Why, even after his imprisonment, people keep calling Hannibal Lecter "Doctor"?

May I know how to stop these death waves?

I transpose the source code, you transpose the input!

Why does C++ have 'Undefined Behaviour' and other languages like C# or Java don't?

irrational fear of hell and damnation and spiralling, please help me?

Why did UK NHS pay for homeopathic treatments?

Algorithm that generates orthogonal vectors: C++ implementation

What should I consider when deciding whether to delay an exam?

What happens to a net with the Returning Weapon artificer infusion after it hits?

Why is STARTTLS still used?

Hangman Game (YAHG)

How to justify getting additional team member when the current team is doing well?

Why does (inf + 0j)*1 evaluate to inf + nanj?

Difference between "rip up" and "rip down"

Beyond Futuristic Technology for an Alien Warship?

Character Transformation

How 象【しょう】 ( ≈かたち、 すがた、ようす) and 象【ぞう】 (どうぶつ) got to be written with the same kanji?

Youtube not blocked by iptables

Do wheelchair-accessible aircraft exist?

New road bike: alloy dual pivot brakes work poorly

What did Jesse Pinkman mix into Walt's coffee?

Does "as soon as" imply simultaneity?

Is a Middle Name a Given Name?

Do we have any particular tonal center in mind when we are NOT listening music?



Concatenate csv column to string and print specific value


Is there a built-in function to print all the current properties and values of an object?Convert array to CSV/TSV-formated string in PythonPython Print String To Text FileHow can I print literal curly-brace characters in python string and also use .format on it?Concatenate item in list to stringsSelecting and operating on columns in a .csvSelect rows from a DataFrame based on values in a column in pandasPython - Using Input From CSV File/Splitting a StringBuild string by selecting column in csvHow to convert the column to numeric in python for sorting






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a csv file contains three columns: date, time and temperature.



Now I have the following code and need to concatenate date, time and temperature in a temporary string and append the temporary string into an array that holds values where temperature > 80, and print the result.



import csv
data_array = []
output = []

with open("temp.csv") as csvfile:
csv_reader = csv.reader(csvfile, delimiter=",")
next(csv_reader, None)
for row in csv_reader:
data_array.append("date": row[0], "time": row[1], "temp": float(row[2]))
#create an array of dictionary to put related data together; convert the temperature to float.
for item in data_array:
if item['temp'] > 80:

output.append(item)

print(output)


I can only print a dictionary of those items but how can I concatenate items and print a result? Shouldn't I use dictionary?










share|improve this question


























  • I'm confused what your expected output would look like. Could you post a sample?

    – Reedinationer
    Mar 28 at 18:13











  • Sure. like [‘1/2/2018 10:00 AM’, 65.5], [1/2/2018 11:00 AM’, 67.3], …

    – Biu
    Mar 28 at 18:15

















1















I have a csv file contains three columns: date, time and temperature.



Now I have the following code and need to concatenate date, time and temperature in a temporary string and append the temporary string into an array that holds values where temperature > 80, and print the result.



import csv
data_array = []
output = []

with open("temp.csv") as csvfile:
csv_reader = csv.reader(csvfile, delimiter=",")
next(csv_reader, None)
for row in csv_reader:
data_array.append("date": row[0], "time": row[1], "temp": float(row[2]))
#create an array of dictionary to put related data together; convert the temperature to float.
for item in data_array:
if item['temp'] > 80:

output.append(item)

print(output)


I can only print a dictionary of those items but how can I concatenate items and print a result? Shouldn't I use dictionary?










share|improve this question


























  • I'm confused what your expected output would look like. Could you post a sample?

    – Reedinationer
    Mar 28 at 18:13











  • Sure. like [‘1/2/2018 10:00 AM’, 65.5], [1/2/2018 11:00 AM’, 67.3], …

    – Biu
    Mar 28 at 18:15













1












1








1








I have a csv file contains three columns: date, time and temperature.



Now I have the following code and need to concatenate date, time and temperature in a temporary string and append the temporary string into an array that holds values where temperature > 80, and print the result.



import csv
data_array = []
output = []

with open("temp.csv") as csvfile:
csv_reader = csv.reader(csvfile, delimiter=",")
next(csv_reader, None)
for row in csv_reader:
data_array.append("date": row[0], "time": row[1], "temp": float(row[2]))
#create an array of dictionary to put related data together; convert the temperature to float.
for item in data_array:
if item['temp'] > 80:

output.append(item)

print(output)


I can only print a dictionary of those items but how can I concatenate items and print a result? Shouldn't I use dictionary?










share|improve this question
















I have a csv file contains three columns: date, time and temperature.



Now I have the following code and need to concatenate date, time and temperature in a temporary string and append the temporary string into an array that holds values where temperature > 80, and print the result.



import csv
data_array = []
output = []

with open("temp.csv") as csvfile:
csv_reader = csv.reader(csvfile, delimiter=",")
next(csv_reader, None)
for row in csv_reader:
data_array.append("date": row[0], "time": row[1], "temp": float(row[2]))
#create an array of dictionary to put related data together; convert the temperature to float.
for item in data_array:
if item['temp'] > 80:

output.append(item)

print(output)


I can only print a dictionary of those items but how can I concatenate items and print a result? Shouldn't I use dictionary?







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 19:15









mttpgn

2282 silver badges11 bronze badges




2282 silver badges11 bronze badges










asked Mar 28 at 18:11









BiuBiu

165 bronze badges




165 bronze badges















  • I'm confused what your expected output would look like. Could you post a sample?

    – Reedinationer
    Mar 28 at 18:13











  • Sure. like [‘1/2/2018 10:00 AM’, 65.5], [1/2/2018 11:00 AM’, 67.3], …

    – Biu
    Mar 28 at 18:15

















  • I'm confused what your expected output would look like. Could you post a sample?

    – Reedinationer
    Mar 28 at 18:13











  • Sure. like [‘1/2/2018 10:00 AM’, 65.5], [1/2/2018 11:00 AM’, 67.3], …

    – Biu
    Mar 28 at 18:15
















I'm confused what your expected output would look like. Could you post a sample?

– Reedinationer
Mar 28 at 18:13





I'm confused what your expected output would look like. Could you post a sample?

– Reedinationer
Mar 28 at 18:13













Sure. like [‘1/2/2018 10:00 AM’, 65.5], [1/2/2018 11:00 AM’, 67.3], …

– Biu
Mar 28 at 18:15





Sure. like [‘1/2/2018 10:00 AM’, 65.5], [1/2/2018 11:00 AM’, 67.3], …

– Biu
Mar 28 at 18:15












2 Answers
2






active

oldest

votes


















0
















You don't need a temporary list of dicts. Simply build a list of concatenated date and time and the temperature and append the list to the output list when the temperature is greater than 80 directly withint the loop that iterates through the CSV reader:



with open("temp.csv") as csvfile:
csv_reader = csv.reader(csvfile, delimiter=",")
next(csv_reader, None)
for date, time, temperature in csv_reader:
temperature = float(temperature)
if temperature > 80:
output.append([' '.join((date, time)), temperature])





share|improve this answer






















  • 1





    Thank you very much. My second day of python so don't now lots of simple stuff yet.

    – Biu
    Mar 28 at 18:35


















0
















Just change



output.append(item)


To



output.append([' '.format(item['date'], item['time']), item['temp']])





share|improve this answer



























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404288%2fconcatenate-csv-column-to-string-and-print-specific-value%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    You don't need a temporary list of dicts. Simply build a list of concatenated date and time and the temperature and append the list to the output list when the temperature is greater than 80 directly withint the loop that iterates through the CSV reader:



    with open("temp.csv") as csvfile:
    csv_reader = csv.reader(csvfile, delimiter=",")
    next(csv_reader, None)
    for date, time, temperature in csv_reader:
    temperature = float(temperature)
    if temperature > 80:
    output.append([' '.join((date, time)), temperature])





    share|improve this answer






















    • 1





      Thank you very much. My second day of python so don't now lots of simple stuff yet.

      – Biu
      Mar 28 at 18:35















    0
















    You don't need a temporary list of dicts. Simply build a list of concatenated date and time and the temperature and append the list to the output list when the temperature is greater than 80 directly withint the loop that iterates through the CSV reader:



    with open("temp.csv") as csvfile:
    csv_reader = csv.reader(csvfile, delimiter=",")
    next(csv_reader, None)
    for date, time, temperature in csv_reader:
    temperature = float(temperature)
    if temperature > 80:
    output.append([' '.join((date, time)), temperature])





    share|improve this answer






















    • 1





      Thank you very much. My second day of python so don't now lots of simple stuff yet.

      – Biu
      Mar 28 at 18:35













    0














    0










    0









    You don't need a temporary list of dicts. Simply build a list of concatenated date and time and the temperature and append the list to the output list when the temperature is greater than 80 directly withint the loop that iterates through the CSV reader:



    with open("temp.csv") as csvfile:
    csv_reader = csv.reader(csvfile, delimiter=",")
    next(csv_reader, None)
    for date, time, temperature in csv_reader:
    temperature = float(temperature)
    if temperature > 80:
    output.append([' '.join((date, time)), temperature])





    share|improve this answer















    You don't need a temporary list of dicts. Simply build a list of concatenated date and time and the temperature and append the list to the output list when the temperature is greater than 80 directly withint the loop that iterates through the CSV reader:



    with open("temp.csv") as csvfile:
    csv_reader = csv.reader(csvfile, delimiter=",")
    next(csv_reader, None)
    for date, time, temperature in csv_reader:
    temperature = float(temperature)
    if temperature > 80:
    output.append([' '.join((date, time)), temperature])






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 28 at 18:36

























    answered Mar 28 at 18:18









    blhsingblhsing

    50.9k5 gold badges19 silver badges49 bronze badges




    50.9k5 gold badges19 silver badges49 bronze badges










    • 1





      Thank you very much. My second day of python so don't now lots of simple stuff yet.

      – Biu
      Mar 28 at 18:35












    • 1





      Thank you very much. My second day of python so don't now lots of simple stuff yet.

      – Biu
      Mar 28 at 18:35







    1




    1





    Thank you very much. My second day of python so don't now lots of simple stuff yet.

    – Biu
    Mar 28 at 18:35





    Thank you very much. My second day of python so don't now lots of simple stuff yet.

    – Biu
    Mar 28 at 18:35













    0
















    Just change



    output.append(item)


    To



    output.append([' '.format(item['date'], item['time']), item['temp']])





    share|improve this answer





























      0
















      Just change



      output.append(item)


      To



      output.append([' '.format(item['date'], item['time']), item['temp']])





      share|improve this answer



























        0














        0










        0









        Just change



        output.append(item)


        To



        output.append([' '.format(item['date'], item['time']), item['temp']])





        share|improve this answer













        Just change



        output.append(item)


        To



        output.append([' '.format(item['date'], item['time']), item['temp']])






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 18:18









        ReedinationerReedinationer

        4,0831 gold badge4 silver badges27 bronze badges




        4,0831 gold badge4 silver badges27 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404288%2fconcatenate-csv-column-to-string-and-print-specific-value%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해